benchs: update run programs. Remove pep8analysis because it is too fast
[nit.git] / benchmarks / bench_strings.sh
1 #!/bin/bash
2 # This file is part of NIT ( http://www.nitlanguage.org ).
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 source ./bench_common.sh
17 source ./bench_plot.sh
18
19 # Default number of times a command must be run with bench_command
20 # Can be overrided with 'the option -n'
21 count=2
22
23 function usage()
24 {
25 echo "run_bench: [options]* bench_name args"
26 echo " -v: verbose mode"
27 echo " -n count: number of execution for each bar (default: $count)"
28 echo " -h: this help"
29 echo ""
30 echo "Benches : "
31 echo " all : all benches"
32 echo " - usage : * max_nb_cct loops strlen"
33 echo " iter: bench iterations"
34 echo " - usage : iter max_nb_cct loops strlen"
35 echo " cct: concatenation benching"
36 echo " - usage : cct max_nb_cct loops strlen"
37 echo " substr: substring benching"
38 echo " - usage : substr max_nb_cct loops strlen"
39 echo " array: Benchmark for the to_s in array"
40 echo " - usage : array nb_cct loops max_arrlen"
41 }
42
43 function benches()
44 {
45 bench_concat $@;
46 bench_iteration $@;
47 bench_substr $@;
48 bench_array $@;
49 }
50
51 function bench_array()
52 {
53 if $verbose; then
54 echo "*** Benching Array.to_s performance ***"
55 fi
56
57 ../bin/nitg --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_rope.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
58
59 prepare_res arr_tos_ropes.out arr_tos_ropes ropes
60 if $verbose; then
61 echo "Ropes :"
62 fi
63 for i in `seq 1 "$3"`; do
64 if $verbose; then
65 echo "String length = $i, Concats/loop = $1, Loops = $2"
66 fi
67 bench_command $i ropes$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
68 done
69
70 ../bin/nitg --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_flatstr.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
71
72 prepare_res arr_tos_flat.out arr_tos_flat flatstring
73 if $verbose; then
74 echo "FlatStrings :"
75 fi
76 for i in `seq 1 "$3"`; do
77 if $verbose; then
78 echo "String length = $i, Concats/loop = $1, Loops = $2"
79 fi
80 bench_command $i flatstring$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
81 done
82
83 ../bin/nitg --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_buffer.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
84
85 prepare_res arr_tos_buf.out arr_tos_buf flatbuffer
86 if $verbose; then
87 echo "FlatBuffers :"
88 fi
89 for i in `seq 1 "$3"`; do
90 if $verbose; then
91 echo "String length = $i, Concats/loop = $1, Loops = $2"
92 fi
93 bench_command $i flatbuffer$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
94 done
95
96 ../bin/nitg --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_manual.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
97
98 prepare_res arr_tos_man.out arr_tos_man memmove
99 if $verbose; then
100 echo "Memmove :"
101 fi
102 for i in `seq 1 "$3"`; do
103 if $verbose; then
104 echo "String length = $i, Concats/loop = $1, Loops = $2"
105 fi
106 bench_command $i memmove$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
107 done
108
109 ../bin/nitg --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_man_buf.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
110
111 prepare_res arr_tos_man_buf.out arr_tos_man_buf flatbuf_with_capacity
112 if $verbose; then
113 echo "Memmove :"
114 fi
115 for i in `seq 1 "$3"`; do
116 if $verbose; then
117 echo "String length = $i, Concats/loop = $1, Loops = $2"
118 fi
119 bench_command $i flatbuf_with_capacity$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
120 done
121
122 plot array_tos.gnu
123 }
124
125 function bench_concat()
126 {
127 if $verbose; then
128 echo "*** Benching concat performance ***"
129 fi
130
131 prepare_res concat_ropes.out concat_ropes ropes
132 if $verbose; then
133 echo "Ropes :"
134 fi
135 for i in `seq 1 "$1"`; do
136 if $verbose; then
137 echo "String length = $i, Concats/loop = $2, Loops = $3"
138 fi
139 bench_command $i ropes$i ./chain_concat -m rope --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
140 done
141
142 prepare_res concat_flat.out concat_flat flatstring
143 if $verbose; then
144 echo "FlatStrings :"
145 fi
146 for i in `seq 1 "$1"`; do
147 if $verbose; then
148 echo "String length = $i, Concats/loop = $2, Loops = $3"
149 fi
150 bench_command $i flatstring$i ./chain_concat -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
151 done
152
153 prepare_res concat_buf.out concat_buf flatbuffer
154 if $verbose; then
155 echo "FlatBuffers :"
156 fi
157 for i in `seq 1 "$1"`; do
158 if $verbose; then
159 echo "String length = $i, Concats/loop = $2, Loops = $3"
160 fi
161 bench_command $i flatbuffer$i ./chain_concat -m flatbuf --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
162 done
163
164 prepare_res concat_flatstr_utf8_noindex.out concat_flatstr_utf8_noindex flatstring_utf8_noindex
165 if $verbose; then
166 echo "FlatString UTF-8 (without index) :"
167 fi
168 for i in `seq 1 "$1"`; do
169 if $verbose; then
170 echo "String length = $i, Concats/loop = $2, Loops = $3"
171 fi
172 bench_command $i flatstr_utf8_noindex$i ./utf_chain_concat -m flatstr_utf8_noindex --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
173 done
174
175 plot concat.gnu
176 }
177
178 function bench_iteration()
179 {
180 if $verbose; then
181 echo "*** Benching iteration performance ***"
182 fi
183
184 prepare_res iter_ropes_iter.out iter_ropes_iter ropes_iter
185 if $verbose; then
186 echo "Ropes by iterator :"
187 fi
188 for i in `seq 1 "$1"`; do
189 if $verbose; then
190 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
191 fi
192 bench_command $i ropes_iter$i ./iteration_bench -m rope --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
193 done
194
195 prepare_res iter_ropes_index.out iter_ropes_index ropes_index
196 if $verbose; then
197 echo "Ropes by index :"
198 fi
199 for i in `seq 1 "$1"`; do
200 if $verbose; then
201 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
202 fi
203 bench_command $i ropes_index$i ./iteration_bench -m rope --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
204 done
205
206 prepare_res iter_flat_iter.out iter_flat_iter flatstring_iter
207 if $verbose; then
208 echo "FlatStrings by iterator :"
209 fi
210 for i in `seq 1 "$1"`; do
211 if $verbose; then
212 echo "String base length = $1, Concats = $i, Loops = $3"
213 fi
214 bench_command $i flatstr_iter$i ./iteration_bench -m flatstr --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
215 done
216
217 prepare_res iter_flat_index.out iter_flat_index flatstring_index
218 if $verbose; then
219 echo "FlatStrings by index :"
220 fi
221 for i in `seq 1 "$1"`; do
222 if $verbose; then
223 echo "String base length = $1, Concats = $i, Loops = $3"
224 fi
225 bench_command $i flatstr_index$i ./iteration_bench -m flatstr --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
226 done
227
228 prepare_res iter_buf_iter.out iter_buf_iter flatbuffer_iter
229 if $verbose; then
230 echo "FlatBuffers by iterator :"
231 fi
232 for i in `seq 1 "$1"`; do
233 if $verbose; then
234 echo "String base length = $1, Concats = $i, Loops = $3"
235 fi
236 bench_command $i flatbuf_iter$i ./iteration_bench -m flatbuf --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
237 done
238
239 prepare_res iter_buf_index.out iter_buf_index flatbuffer_index
240 if $verbose; then
241 echo "FlatBuffers by index:"
242 fi
243 for i in `seq 1 "$1"`; do
244 if $verbose; then
245 echo "String base length = $1, Concats = $i, Loops = $3"
246 fi
247 bench_command $i flatbuf_index$i ./iteration_bench -m flatbuf --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
248 done
249
250 prepare_res iter_flat_utf8_noindex_iter.out iter_flat_iter_utf8_noindex flatstring_utf8_noindex_iter
251 if $verbose; then
252 echo "FlatStrings by iterator :"
253 fi
254 for i in `seq 1 "$1"`; do
255 if $verbose; then
256 echo "String base length = $1, Concats = $i, Loops = $3"
257 fi
258 bench_command $i flatstr_iter_utf8_noindex$i ./utf_iteration_bench -m flatstr_utf8_noindex --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
259 done
260
261 prepare_res iter_flat_utf8_noindex_index.out iter_flat_index_utf8_noindex flatstring_utf8_noindex_index
262 if $verbose; then
263 echo "FlatStrings by index :"
264 fi
265 for i in `seq 1 "$1"`; do
266 if $verbose; then
267 echo "String base length = $1, Concats = $i, Loops = $3"
268 fi
269 bench_command $i flatstr_index_utf8_noindex$i ./utf_iteration_bench -m flatstr_utf8_noindex --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
270 done
271
272 plot iter.gnu
273 }
274
275 function bench_substr()
276 {
277 if $verbose; then
278 echo "*** Benching substring performance ***"
279 fi
280
281 prepare_res substr_ropes.out substr_ropes ropes
282 if $verbose; then
283 echo "Ropes :"
284 fi
285 for i in `seq 1 "$1"`; do
286 if $verbose; then
287 echo "String length = $i, loops = $2, Loops = $3"
288 fi
289 bench_command $i ropes$i ./substr_bench -m rope --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
290 done
291
292 prepare_res substr_flat.out substr_flat flatstring
293 if $verbose; then
294 echo "FlatStrings :"
295 fi
296 for i in `seq 1 "$1"`; do
297 if $verbose; then
298 echo "String length = $i, loops = $2, Loops = $3"
299 fi
300 bench_command $i flatstring$i ./substr_bench -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
301 done
302
303 prepare_res substr_buf.out substr_buf flatbuffer
304 if $verbose; then
305 echo "FlatBuffers :"
306 fi
307 for i in `seq 1 "$1"`; do
308 if $verbose; then
309 echo "String length = $i, loops = $2, Loops = $3"
310 fi
311 bench_command $i flatbuffer$i ./substr_bench -m flatbuf --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
312 done
313
314 prepare_res substr_flat_utf8_noindex.out substr_flat_utf8_noindex flatstring_utf8_noindex
315 if $verbose; then
316 echo "FlatStrings UTF-8 (without index) :"
317 fi
318 for i in `seq 1 "$1"`; do
319 if $verbose; then
320 echo "String length = $i, loops = $2, Loops = $3"
321 fi
322 bench_command $i flatstring_utf8_noindex$i ./utf_substr_bench -m flatstr_utf8_noindex --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
323 done
324
325 plot substr.gnu
326 }
327
328 stop=false
329 while [ "$stop" = false ]; do
330 case "$1" in
331 -v) verbose=true; shift;;
332 -h) usage; exit;;
333 -n) count="$2"; shift; shift;;
334 *) stop=true
335 esac
336 done
337
338 if test $# -ne 4; then
339 usage
340 exit
341 fi
342
343 if $verbose; then
344 echo "Compiling"
345 fi
346
347 ../bin/nitg --global ./strings/chain_concat.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
348 ../bin/nitg --global ./strings/utf_chain_concat.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
349 ../bin/nitg --global ./strings/iteration_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
350 ../bin/nitg --global ./strings/utf_iteration_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
351 ../bin/nitg --global ./strings/substr_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
352 ../bin/nitg --global ./strings/utf_substr_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
353
354 case "$1" in
355 iter) shift; bench_iteration $@ ;;
356 cct) shift; bench_concat $@ ;;
357 substr) shift; bench_substr $@ ;;
358 array) shift; bench_array $@ ;;
359 all) shift; benches $@ ;;
360 *) usage; exit;;
361 esac