-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_perf_stats.bash
executable file
·203 lines (160 loc) · 7.13 KB
/
gen_perf_stats.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
# writes a perf summary as a markdown file to stdout
set -e
sudo echo -n '' # do nothing. perf requires sudo. doing the prompt at the beginning
# fairer performance for sort
export LC_ALL=C
# e.g. -n makes the benchmarks apply sorting and uniqueness numerically (but not for just uniqueness since awk doesn't support this)
COMP_FLAGS=
# e.g. --unique-use-set or --load-factor
UNIQUE_FLAGS=
# e.g. must be -u or --uniq
SORT_UNIQUE_FLAGS=-u
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# point to different perf paths for issues like this: https://github.com/microsoft/WSL/issues/9917
# invoke like: PERF_TOOL=/usr/lib/linux-tools/5.4.0-155-generic/perf ./gen_perf_stats.bash
PERF_TOOL="${PERF_TOOL:-perf}"
if ! command -v "$PERF_TOOL" &> /dev/null ; then
echo "$PERF_TOOL could not be found. typically needs apt package linux-tools-generic"
exit 1
fi
CHOOSE_PATH=~/.choose/choose
if ! command -v "$CHOOSE_PATH" &> /dev/null ; then
echo "choose couldn't be found."
echo " - make sure it's installed"
echo " - try running this script without sudo (since choose is installed under user dir)"
exit 1
fi
if [ ! -e "$SCRIPT_DIR/plain_text.txt" ]; then
echo "generating plain_text.txt"
wget -q https://www.gutenberg.org/files/1342/1342-0.txt
for i in {1..65}
do
cat 1342-0.txt >> "$SCRIPT_DIR/plain_text.txt"
done
rm 1342-0.txt
truncate -s 50000000 "$SCRIPT_DIR/plain_text.txt"
fi
if [ ! -e "$SCRIPT_DIR/test_repeated.txt" ]; then
echo "generating test_repeated.txt"
yes "test" | head -n 10000000 > "$SCRIPT_DIR/test_repeated.txt"
fi
if [ ! -e "$SCRIPT_DIR/no_duplicates.txt" ]; then
echo "generating no_duplicates.txt"
seq 6388888 > "$SCRIPT_DIR/no_duplicates.txt"
fi
if [ ! -e "$SCRIPT_DIR/csv_field.txt" ]; then
echo "generating csv_field.txt (might take a while...)"
(for i in {1..2129629} ; do
echo garbage,$i,garbage
done) > "$SCRIPT_DIR/csv_field.txt"
fi
run_get_time() {
echo -n $(2>&1 sudo "$PERF_TOOL" stat --field-separator " " -- "${@:2}" < "$1" > /dev/null) | cut -d " " -f1 | tr -d '\n'
echo -n " | "
}
echo -e "### Versions\n\`\`\`txt"
choose --version
pcre2grep --version
sed --version | head -n 1
awk --version | head -n 1
sort --version | head -n 1
echo -e "\`\`\`\n### Specs\n\`\`\`txt"
uname -r
if command -v lscpu &> /dev/null ; then
lscpu | grep -oP '^Model name: *\K.*' --color=never
fi
echo -n "ram: "
cat /proc/meminfo | grep -oP '^MemTotal: *\K.*' --color=never
echo -en "\`\`\`\\n
### Grepping
| (ms) | choose | pcre2grep |
|------------------|--------|------------|
| plain_text | "
run_get_time "$SCRIPT_DIR/plain_text.txt" "$CHOOSE_PATH" -f test
run_get_time "$SCRIPT_DIR/plain_text.txt" pcre2grep test
echo -en "\n| test_repeated | "
run_get_time "$SCRIPT_DIR/test_repeated.txt" "$CHOOSE_PATH" -f test
run_get_time "$SCRIPT_DIR/test_repeated.txt" pcre2grep test
echo -en "\n| no_duplicates | "
run_get_time "$SCRIPT_DIR/no_duplicates.txt" "$CHOOSE_PATH" -f test
run_get_time "$SCRIPT_DIR/no_duplicates.txt" pcre2grep test
echo -en "\n\n\
### Stream Editing
| (ms) | choose | sed |
|------------------|--------|------|
| plain_text | "
run_get_time "$SCRIPT_DIR/plain_text.txt" "$CHOOSE_PATH" --sed test --replace banana
run_get_time "$SCRIPT_DIR/plain_text.txt" sed -z "s/test/banana/g"
echo -en "\n| test_repeated | "
run_get_time "$SCRIPT_DIR/test_repeated.txt" "$CHOOSE_PATH" --sed test --replace banana
run_get_time "$SCRIPT_DIR/test_repeated.txt" sed -z "s/test/banana/g"
echo -en "\n| no_duplicates | "
run_get_time "$SCRIPT_DIR/no_duplicates.txt" "$CHOOSE_PATH" --sed test --replace banana
run_get_time "$SCRIPT_DIR/no_duplicates.txt" sed -z "s/test/banana/g"
echo -en "\n\n(here is a cherry picked great case for choose compared to sed)
| (ms) | choose | sed (with newline delimiter) |
|------------------|--------|------|
| no_duplicates | "
run_get_time "$SCRIPT_DIR/no_duplicates.txt" "$CHOOSE_PATH" --sed test --replace banana
run_get_time "$SCRIPT_DIR/no_duplicates.txt" sed "s/test/banana/g"
echo -en "\n\n(a special case, where choose cheats by using a literal replacement string)
| (ms) | choose (delimiter sub) | sed |
|------------------|------------------------|-----|
| test_repeated | "
run_get_time "$SCRIPT_DIR/test_repeated.txt" "$CHOOSE_PATH" test -o banana -d
run_get_time "$SCRIPT_DIR/test_repeated.txt" sed -z "s/test/banana/g"
echo -en "\n\n\
### Sorting $COMP_FLAGS
| (ms) | choose | sort |
|------------------|--------|------|
| plain_text | "
run_get_time "$SCRIPT_DIR/plain_text.txt" "$CHOOSE_PATH" -s $COMP_FLAGS
run_get_time "$SCRIPT_DIR/plain_text.txt" sort $COMP_FLAGS
echo -en "\n| test_repeated | "
run_get_time "$SCRIPT_DIR/test_repeated.txt" "$CHOOSE_PATH" -s $COMP_FLAGS
run_get_time "$SCRIPT_DIR/test_repeated.txt" sort $COMP_FLAGS
echo -en "\n| no_duplicates | "
run_get_time "$SCRIPT_DIR/no_duplicates.txt" "$CHOOSE_PATH" -s $COMP_FLAGS
run_get_time "$SCRIPT_DIR/no_duplicates.txt" sort $COMP_FLAGS
echo -en "\n\n(a special case that leverages truncation)\n\
| (ms) | choose -s --out 5 | sort \| head -n 5 |
|------------------|--------|------|
| no_duplicates | "
run_get_time "$SCRIPT_DIR/no_duplicates.txt" "$CHOOSE_PATH" -s --out 5 $COMP_FLAGS
run_get_time "$SCRIPT_DIR/no_duplicates.txt" sort $COMP_FLAGS | head -n 5
echo -en "\n\n\
### Uniqueness $UNIQUE_FLAGS
| (ms) | choose | awk |
|------------------|--------|-----|
| plain_text | "
run_get_time "$SCRIPT_DIR/plain_text.txt" "$CHOOSE_PATH" -u $UNIQUE_FLAGS
run_get_time "$SCRIPT_DIR/plain_text.txt" awk '!a[$0]++'
echo -en "\n| test_repeated | "
run_get_time "$SCRIPT_DIR/test_repeated.txt" "$CHOOSE_PATH" -u $UNIQUE_FLAGS
run_get_time "$SCRIPT_DIR/test_repeated.txt" awk '!a[$0]++'
echo -en "\n| no_duplicates | "
run_get_time "$SCRIPT_DIR/no_duplicates.txt" "$CHOOSE_PATH" -u $UNIQUE_FLAGS
run_get_time "$SCRIPT_DIR/no_duplicates.txt" awk '!a[$0]++'
echo -en "\n\n\
### Sorting and Uniqueness $COMP_FLAGS $UNIQUE_FLAGS $SORT_UNIQUE_FLAGS
| (ms) | choose | sort |
|------------------|--------|------|
| plain_text | "
run_get_time "$SCRIPT_DIR/plain_text.txt" "$CHOOSE_PATH" -s $COMP_FLAGS $UNIQUE_FLAGS $SORT_UNIQUE_FLAGS
run_get_time "$SCRIPT_DIR/plain_text.txt" sort -u $COMP_FLAGS
echo -en "\n| test_repeated | "
run_get_time "$SCRIPT_DIR/test_repeated.txt" "$CHOOSE_PATH" -s $COMP_FLAGS $UNIQUE_FLAGS $SORT_UNIQUE_FLAGS
run_get_time "$SCRIPT_DIR/test_repeated.txt" sort -u $COMP_FLAGS
echo -en "\n| no_duplicates | "
run_get_time "$SCRIPT_DIR/no_duplicates.txt" "$CHOOSE_PATH" -s $COMP_FLAGS $UNIQUE_FLAGS $SORT_UNIQUE_FLAGS
run_get_time "$SCRIPT_DIR/no_duplicates.txt" sort -u $COMP_FLAGS
echo ""
echo -en "\n\n\
### Sorting and Uniqueness based on field $COMP_FLAGS $UNIQUE_FLAGS $SORT_UNIQUE_FLAGS
| (ms) | choose | sort |
|------------------|--------|------|
| csv_field | "
run_get_time "$SCRIPT_DIR/csv_field.txt" "$CHOOSE_PATH" -s --field '^[^,]*+.\K[^,]*+' $COMP_FLAGS $UNIQUE_FLAGS $SORT_UNIQUE_FLAGS
run_get_time "$SCRIPT_DIR/csv_field.txt" sort -u -t, -k2 $COMP_FLAGS
echo ""