-
Notifications
You must be signed in to change notification settings - Fork 7
/
gen_images.sh
executable file
·261 lines (245 loc) · 7.99 KB
/
gen_images.sh
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/sh
CC="gcc -std=c11"
CXX="g++ -std=c++17"
CFLAGS="-O3 -march=native -I."
VERSION=$($CXX --version | head -1)
if test -z "$PNG"; then
PNG="uset uset_pow2 uset_cached _set pqu vec slist list deq arr compile"
fi
perf_graph()
{
LOG=$1
TITLE=$2
LIST=$3
OUT=bin
echo "$LOG"
for TEST in $LIST
do
# allow glob expansion of CFLAGS and TEST lists
# shellcheck disable=SC2086
case $TEST in
*.c) $CC -o "$OUT" $CFLAGS $TEST -I.
;;
*.cc) $CXX -o "$OUT" $CFLAGS $TEST
;;
esac
./$OUT >> "$LOG"
done
python3 tests/perf/perf_plot.py "$LOG" "$TITLE" &&
(mv "./$LOG.png" docs/images/; mv "./$LOG" tests/perf/; rm -- "./$OUT")
}
perf_compile_two_bar()
{
KEY='stamp'
TIME="$KEY %e %M"
LOG="$1"
TITLE="$2"
A="$3"
B="$4"
DEF="$5"
AA=bina
BB=binb
echo "$LOG"
# allow glob expansion of CFLAGS
# shellcheck disable=SC2086
echo time $CC -o $AA $CFLAGS $DEF "$A" -I.
# warmup
$CC -o $AA $CFLAGS $DEF "$A" -I. 2>&1
X=$(/bin/time -f "$TIME" $CC -o $AA $CFLAGS $DEF "$A" -I. 2>&1 | grep $KEY)
TIME_A=$(echo $X | cut -d ' ' -f 2)
MEM_A=$(echo $X | cut -d ' ' -f 3)
strip $AA
SIZE_A=$(stat --printf="%s" $AA)
echo "$X: $TIME_A sec $MEM_A k RSS $SIZE_A KB"
# shellcheck disable=SC2086
echo time $CXX -o $BB $CFLAGS $DEF "$B"
Y=$(/bin/time -f "$TIME" $CXX -o $BB $CFLAGS $DEF "$B" 2>&1 | grep $KEY)
TIME_B=$(echo $Y | cut -d ' ' -f 2)
MEM_B=$(echo $Y | cut -d ' ' -f 3)
strip $BB
SIZE_B=$(stat --printf="%s" $BB)
echo "$Y: $TIME_B sec $MEM_B k RSS $SIZE_B KB"
python3 tests/perf/perf_plot_bar.py "$LOG" "$TITLE" "$TIME_A" "$TIME_B" \
"$SIZE_A" "$SIZE_B" "$MEM_A" "$MEM_B" "$A" "$B" &&
(mv "$LOG.png" docs/images/; rm -- "./$AA" "./$BB")
}
uset() {
perf_graph \
'uset.log' \
"std::unordered_set<int> (dotted) vs. CTL uset_int (solid) ($CFLAGS) ($VERSION)" \
"tests/perf/uset/perf_uset_insert.cc \
tests/perf/uset/perf_uset_insert.c \
tests/perf/uset/perf_uset_erase.cc \
tests/perf/uset/perf_uset_erase.c
tests/perf/uset/perf_uset_iterate.cc \
tests/perf/uset/perf_uset_iterate.c"
}
uset_pow2() {
ORIG_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -DCTL_USET_GROWTH_POWER2"
perf_graph \
'uset_pow2.log' \
"std::unordered_set<int> (dotted) vs. CTL uset_int POWER2 (solid) ($CFLAGS) ($VERSION)" \
"tests/perf/uset/perf_uset_insert.cc \
tests/perf/uset/perf_uset_insert.c \
tests/perf/uset/perf_uset_erase.cc \
tests/perf/uset/perf_uset_erase.c
tests/perf/uset/perf_uset_iterate.cc \
tests/perf/uset/perf_uset_iterate.c"
CFLAGS="$ORIG_CFLAGS"
}
uset_cached() {
ORIG_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -DCTL_USET_CACHED_HASH"
perf_graph \
'uset_cached.log' \
"std::unordered_set<int> (dotted) vs. CTL uset_int CACHED_HASH (solid) ($CFLAGS) ($VERSION)" \
"tests/perf/uset/perf_uset_insert.cc \
tests/perf/uset/perf_uset_insert.c \
tests/perf/uset/perf_uset_erase.cc \
tests/perf/uset/perf_uset_erase.c
tests/perf/uset/perf_uset_iterate.cc \
tests/perf/uset/perf_uset_iterate.c"
CFLAGS="$ORIG_CFLAGS"
}
_set() {
perf_graph \
'set.log' \
"std::set<int> (dotted) vs. CTL set_int (solid) ($CFLAGS) ($VERSION)" \
"tests/perf/set/perf_set_insert.cc \
tests/perf/set/perf_set_insert.c \
tests/perf/set/perf_set_erase.cc \
tests/perf/set/perf_set_erase.c \
tests/perf/set/perf_set_clear.cc \
tests/perf/set/perf_set_clear.c \
tests/perf/set/perf_set_iterate.cc \
tests/perf/set/perf_set_iterate.c"
}
pqu() {
perf_graph \
'pqu.log' \
"std::priority_queue<int> (dotted) vs. CTL pqu_int (solid) ($CFLAGS) ($VERSION)" \
"tests/perf/pqu/perf_priority_queue_push.cc \
tests/perf/pqu/perf_pqu_push.c \
tests/perf/pqu/perf_priority_queue_pop.cc \
tests/perf/pqu/perf_pqu_pop.c \
tests/perf/pqu/perf_priority_queue_top.cc \
tests/perf/pqu/perf_pqu_top.c"
}
vec() {
perf_graph \
'vec.log' \
"std::vector<int> (dotted) vs. CTL vec_int (solid) ($CFLAGS) ($VERSION)" \
"tests/perf/vec/perf_vector_push_back.cc \
tests/perf/vec/perf_vec_push_back.c \
tests/perf/vec/perf_vector_pop_back.cc \
tests/perf/vec/perf_vec_pop_back.c \
tests/perf/vec/perf_vector_sort.cc \
tests/perf/vec/perf_vec_sort.c \
tests/perf/vec/perf_vector_iterate.cc \
tests/perf/vec/perf_vec_iterate.c"
}
str() {
perf_graph \
'str.log' \
"std::string (dotted) vs. CTL str (solid) ($CFLAGS) ($VERSION)" \
"tests/perf/str/perf_string_push_back.cc \
tests/perf/str/perf_str_push_back.c \
tests/perf/str/perf_string_erase.cc \
tests/perf/str/perf_str_erase.c \
tests/perf/str/perf_string_sort.cc \
tests/perf/str/perf_str_sort.c \
tests/perf/str/perf_string_iterate.cc \
tests/perf/str/perf_str_iterate.c"
}
slist() {
perf_graph \
'slist.log' \
"std::forward_list<int> (dotted) vs. CTL slist_int (solid) ($CFLAGS) ($VERSION)" \
"tests/perf/slist/perf_fwlist_pop_front.cc \
tests/perf/slist/perf_slist_pop_front.c \
tests/perf/slist/perf_fwlist_push_front.cc \
tests/perf/slist/perf_slist_push_front.c \
tests/perf/slist/perf_fwlist_sort.cc \
tests/perf/slist/perf_slist_sort.c \
tests/perf/slist/perf_fwlist_iterate.cc \
tests/perf/slist/perf_slist_iterate.c"
}
list() {
perf_graph \
'list.log' \
"std::list<int> (dotted) vs. CTL list_int (solid) ($CFLAGS) ($VERSION)" \
"tests/perf/lst/perf_list_push_back.cc
tests/perf/lst/perf_lst_push_back.c \
tests/perf/lst/perf_list_pop_back.cc \
tests/perf/lst/perf_lst_pop_back.c \
tests/perf/lst/perf_list_push_front.cc \
tests/perf/lst/perf_lst_push_front.c \
tests/perf/lst/perf_list_sort.cc \
tests/perf/lst/perf_lst_sort.c \
tests/perf/lst/perf_list_iterate.cc \
tests/perf/lst/perf_lst_iterate.c"
# removed the one most boring:
# tests/perf/lst/perf_list_pop_front.cc
# tests/perf/lst/perf_lst_pop_front.c
}
deq() {
perf_graph \
'deq.log' \
"std::deque<int> (dotted) vs. CTL deq_int (solid) ($CFLAGS) ($VERSION)" \
"tests/perf/deq/perf_deque_push_back.cc
tests/perf/deq/perf_deq_push_back.c \
tests/perf/deq/perf_deque_pop_back.cc \
tests/perf/deq/perf_deq_pop_back.c \
tests/perf/deq/perf_deque_pop_front.cc \
tests/perf/deq/perf_deq_pop_front.c \
tests/perf/deq/perf_deque_sort.cc \
tests/perf/deq/perf_deq_sort.c \
tests/perf/deq/perf_deque_iterate.cc \
tests/perf/deq/perf_deq_iterate.c"
# removed the one most boring:
# tests/perf/deq/perf_deque_push_front.cc
# tests/perf/deq/perf_deq_push_front.c
}
arr() {
rm tests/perf/arr/gen_arr*
make tests/perf/arr/perf_arr_generate && tests/perf/arr/perf_arr_generate
for TEST in tests/perf/arr/gen_array*.cc; do
$CXX -o "${TEST//.cc/}" $CFLAGS $TEST -I.
done
for TEST in tests/perf/arr/gen_arr*.c; do
$CC -o "${TEST//.c/}" $CFLAGS $TEST -I.
done
LOG=arr.log
TITLE="std::array<double,NNN> (dotted) vs. CTL arrNNN_double (solid) ($CFLAGS) ($VERSION)"
echo "$LOG"
rm -- "./$LOG"
for m in find fill_n sort iterate
do
echo "tests/perf/arr/gen_array_$m.cc" >> "$LOG"
for OUT in tests/perf/arr/gen_array*_$m; do
$OUT >> "$LOG"
done
echo "tests/perf/arr/gen_arr_$m.c" >> "$LOG"
for OUT in tests/perf/arr/gen_arr0*_$m; do
$OUT >> "$LOG"
done
done
python3 tests/perf/perf_plot.py "$LOG" "$TITLE" &&
(mv "$LOG.png" docs/images/; mv $LOG tests/perf/; rm tests/perf/arr/gen_arr* )
}
compile() {
perf_compile_two_bar \
'compile.log' \
"CTL vs STL Compilation ($CFLAGS) ($VERSION)" \
'tests/perf/perf_compile_c11.c' \
'tests/perf/perf_compile_cc.cc' ''
perf_compile_two_bar \
'compile_algorithm.log' \
"CTL vs STL Compilation w/algorithm ($CFLAGS -DALGORITHM) ($VERSION)" \
'tests/perf/perf_compile_c11.c' \
'tests/perf/perf_compile_cc.cc' '-DALGORITHM'
}
for png in $PNG; do
$png
done