update NOTICE
[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/nitc --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_flatstr.nit -m ../lib/standard/ropes.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/nitc --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_flatstr.nit -m ../lib/standard/ropes.nit -m ../lib/buffered_ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
71
72 prepare_res arr_tos_buf_ropes.out arr_tos_buf_ropes buffered_ropes
73 if $verbose; then
74 echo "Buffered Ropes :"
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 buf_ropes$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
81 done
82
83 ../bin/nitc --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_flatstr.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
84
85 prepare_res arr_tos_flat.out arr_tos_flat flatstring
86 if $verbose; then
87 echo "FlatStrings :"
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 flatstring$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
94 done
95
96 ../bin/nitc --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_buffer.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
97
98 prepare_res arr_tos_buf.out arr_tos_buf flatbuffer
99 if $verbose; then
100 echo "FlatBuffers :"
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 flatbuffer$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
107 done
108
109 ../bin/nitc --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_manual.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
110
111 prepare_res arr_tos_man.out arr_tos_man memmove
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 memmove$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
120 done
121
122 ../bin/nitc --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_man_buf.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
123
124 prepare_res arr_tos_man_buf.out arr_tos_man_buf flatbuf_with_capacity
125 if $verbose; then
126 echo "FlatBuffer.with_capacity :"
127 fi
128 for i in `seq 1 "$3"`; do
129 if $verbose; then
130 echo "String length = $i, Concats/loop = $1, Loops = $2"
131 fi
132 bench_command $i flatbuf_with_capacity$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
133 done
134
135 ../bin/nitc --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_rope_buf.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
136
137 prepare_res arr_tos_rope_buf.out arr_tos_rope_buf ropebuf
138 if $verbose; then
139 echo "RopeBuffer :"
140 fi
141 for i in `seq 1 "$3"`; do
142 if $verbose; then
143 echo "String length = $i, Concats/loop = $1, Loops = $2"
144 fi
145 bench_command $i ropebuf$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
146 done
147
148 plot array_tos.gnu
149 }
150
151 function bench_concat()
152 {
153 ../bin/nitc --global ./strings/chain_concat.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
154 ../bin/nitc --global ./strings/utf_chain_concat.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
155
156 if $verbose; then
157 echo "*** Benching concat performance ***"
158 fi
159
160 prepare_res concat_flat.out concat_flat flatstring
161 if $verbose; then
162 echo "FlatStrings :"
163 fi
164 for i in `seq 1 "$1"`; do
165 if $verbose; then
166 echo "String length = $i, Concats/loop = $2, Loops = $3"
167 fi
168 bench_command $i flatstring$i ./chain_concat -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
169 done
170
171 prepare_res concat_buf.out concat_buf flatbuffer
172 if $verbose; then
173 echo "FlatBuffers :"
174 fi
175 for i in `seq 1 "$1"`; do
176 if $verbose; then
177 echo "String length = $i, Concats/loop = $2, Loops = $3"
178 fi
179 bench_command $i flatbuffer$i ./chain_concat -m flatbuf --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
180 done
181
182 prepare_res concat_flatstr_utf8_noindex.out concat_flatstr_utf8_noindex flatstring_utf8_noindex
183 if $verbose; then
184 echo "FlatString UTF-8 (without index) :"
185 fi
186 for i in `seq 1 "$1"`; do
187 if $verbose; then
188 echo "String length = $i, Concats/loop = $2, Loops = $3"
189 fi
190 bench_command $i flatstr_utf8_noindex$i ./utf_chain_concat -m flatstr_utf8_noindex --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
191 done
192
193 ../bin/nitc --global ./strings/chain_concat.nit -m ../lib/standard/ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
194
195 prepare_res concat_ropes.out concat_ropes ropes
196 if $verbose; then
197 echo "Ropes :"
198 fi
199 for i in `seq 1 "$1"`; do
200 if $verbose; then
201 echo "String length = $i, Concats/loop = $2, Loops = $3"
202 fi
203 bench_command $i ropes$i ./chain_concat -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
204 done
205
206 ../bin/nitc --global ./strings/chain_concat.nit -m ../lib/standard/ropes.nit -m ../lib/buffered_ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
207
208 prepare_res concat_buf_ropes.out concat_buf_ropes buffered_ropes
209 if $verbose; then
210 echo "buffered ropes :"
211 fi
212 for i in `seq 1 "$1"`; do
213 if $verbose; then
214 echo "string length = $i, concats/loop = $2, loops = $3"
215 fi
216 bench_command $i buf_ropes$i ./chain_concat -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
217 done
218
219 ../bin/nitc --global ./strings/chain_cct_ropebuf.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
220
221 prepare_res cct_buf_ropes.out cct_buf_ropes cctbuf_ropes
222 if $verbose; then
223 echo "buffered ropes :"
224 fi
225 for i in `seq 1 "$1"`; do
226 if $verbose; then
227 echo "string length = $i, concats/loop = $2, loops = $3"
228 fi
229 bench_command $i cctbuf_ropes$i ./chain_cct_ropebuf --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
230 done
231
232 plot concat.gnu
233 }
234
235 function bench_iteration()
236 {
237 if $verbose; then
238 echo "*** Benching iteration performance ***"
239 fi
240
241 ../bin/nitc --global ./strings/iteration_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
242 ../bin/nitc --global ./strings/utf_iteration_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
243
244 prepare_res iter_flat_iter.out iter_flat_iter flatstring_iter
245 if $verbose; then
246 echo "FlatStrings by iterator :"
247 fi
248 for i in `seq 1 "$1"`; do
249 if $verbose; then
250 echo "String base length = $1, Concats = $i, Loops = $3"
251 fi
252 bench_command $i flatstr_iter$i ./iteration_bench -m flatstr --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
253 done
254
255 prepare_res iter_flat_index.out iter_flat_index flatstring_index
256 if $verbose; then
257 echo "FlatStrings by index :"
258 fi
259 for i in `seq 1 "$1"`; do
260 if $verbose; then
261 echo "String base length = $1, Concats = $i, Loops = $3"
262 fi
263 bench_command $i flatstr_index$i ./iteration_bench -m flatstr --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
264 done
265
266 prepare_res iter_buf_iter.out iter_buf_iter flatbuffer_iter
267 if $verbose; then
268 echo "FlatBuffers by iterator :"
269 fi
270 for i in `seq 1 "$1"`; do
271 if $verbose; then
272 echo "String base length = $1, Concats = $i, Loops = $3"
273 fi
274 bench_command $i flatbuf_iter$i ./iteration_bench -m flatbuf --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
275 done
276
277 prepare_res iter_buf_index.out iter_buf_index flatbuffer_index
278 if $verbose; then
279 echo "FlatBuffers by index:"
280 fi
281 for i in `seq 1 "$1"`; do
282 if $verbose; then
283 echo "String base length = $1, Concats = $i, Loops = $3"
284 fi
285 bench_command $i flatbuf_index$i ./iteration_bench -m flatbuf --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
286 done
287
288 prepare_res iter_flat_utf8_noindex_iter.out iter_flat_iter_utf8_noindex flatstring_utf8_noindex_iter
289 if $verbose; then
290 echo "FlatStrings by iterator :"
291 fi
292 for i in `seq 1 "$1"`; do
293 if $verbose; then
294 echo "String base length = $1, Concats = $i, Loops = $3"
295 fi
296 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"
297 done
298
299 prepare_res iter_flat_utf8_noindex_index.out iter_flat_index_utf8_noindex flatstring_utf8_noindex_index
300 if $verbose; then
301 echo "FlatStrings by index :"
302 fi
303 for i in `seq 1 "$1"`; do
304 if $verbose; then
305 echo "String base length = $1, Concats = $i, Loops = $3"
306 fi
307 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"
308 done
309
310 ../bin/nitc --global ./strings/iteration_bench.nit -m ../lib/standard/ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
311
312 prepare_res iter_ropes_iter.out iter_ropes_iter ropes_iter
313 if $verbose; then
314 echo "Ropes by iterator :"
315 fi
316 for i in `seq 1 "$1"`; do
317 if $verbose; then
318 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
319 fi
320 bench_command $i ropes_iter$i ./iteration_bench -m flatstr --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
321 done
322
323 prepare_res iter_ropes_index.out iter_ropes_index ropes_index
324 if $verbose; then
325 echo "Ropes by index :"
326 fi
327 for i in `seq 1 "$1"`; do
328 if $verbose; then
329 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
330 fi
331 bench_command $i ropes_index$i ./iteration_bench -m flatstr --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
332 done
333
334 ../bin/nitc --global ./strings/iteration_bench.nit -m ../lib/standard/ropes.nit -m ../lib/buffered_ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
335
336 prepare_res iter_buf_ropes_iter.out iter_buf_ropes_iter buf_ropes_iter
337 if $verbose; then
338 echo "Buffered Ropes by iterator :"
339 fi
340 for i in `seq 1 "$1"`; do
341 if $verbose; then
342 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
343 fi
344 bench_command $i buf_ropes_iter$i ./iteration_bench -m flatstr --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
345 done
346
347 prepare_res iter_buf_ropes_index.out iter_buf_ropes_index buf_ropes_index
348 if $verbose; then
349 echo "Buffered Ropes by index :"
350 fi
351 for i in `seq 1 "$1"`; do
352 if $verbose; then
353 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
354 fi
355 bench_command $i buf_ropes_index$i ./iteration_bench -m flatstr --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
356 done
357
358 plot iter.gnu
359 }
360
361 function bench_substr()
362 {
363 if $verbose; then
364 echo "*** Benching substring performance ***"
365 fi
366
367 ../bin/nitc --global ./strings/substr_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
368 ../bin/nitc --global ./strings/utf_substr_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
369
370 prepare_res substr_flat.out substr_flat flatstring
371 if $verbose; then
372 echo "FlatStrings :"
373 fi
374 for i in `seq 1 "$1"`; do
375 if $verbose; then
376 echo "String length = $i, loops = $2, Loops = $3"
377 fi
378 bench_command $i flatstring$i ./substr_bench -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
379 done
380
381 prepare_res substr_buf.out substr_buf flatbuffer
382 if $verbose; then
383 echo "FlatBuffers :"
384 fi
385 for i in `seq 1 "$1"`; do
386 if $verbose; then
387 echo "String length = $i, loops = $2, Loops = $3"
388 fi
389 bench_command $i flatbuffer$i ./substr_bench -m flatbuf --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
390 done
391
392 prepare_res substr_flat_utf8_noindex.out substr_flat_utf8_noindex flatstring_utf8_noindex
393 if $verbose; then
394 echo "FlatStrings UTF-8 (without index) :"
395 fi
396 for i in `seq 1 "$1"`; do
397 if $verbose; then
398 echo "String length = $i, loops = $2, Loops = $3"
399 fi
400 bench_command $i flatstring_utf8_noindex$i ./utf_substr_bench -m flatstr_utf8_noindex --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
401 done
402
403 ../bin/nitc --global ./strings/substr_bench.nit -m ../lib/standard/ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
404
405 prepare_res substr_ropes.out substr_ropes ropes
406 if $verbose; then
407 echo "Ropes :"
408 fi
409 for i in `seq 1 "$1"`; do
410 if $verbose; then
411 echo "String length = $i, loops = $2, Loops = $3"
412 fi
413 bench_command $i ropes$i ./substr_bench -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
414 done
415
416 ../bin/nitc --global ./strings/substr_bench.nit -m ../lib/standard/ropes.nit -m ../lib/buffered_ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
417
418 prepare_res substr_buf_ropes.out substr_buf_ropes buf_ropes
419 if $verbose; then
420 echo "Buffered Ropes :"
421 fi
422 for i in `seq 1 "$1"`; do
423 if $verbose; then
424 echo "String length = $i, loops = $2, Loops = $3"
425 fi
426 bench_command $i buf_ropes$i ./substr_bench -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
427 done
428 plot substr.gnu
429 }
430
431 stop=false
432 while [ "$stop" = false ]; do
433 case "$1" in
434 -v) verbose=true; shift;;
435 -h) usage; exit;;
436 -n) count="$2"; shift; shift;;
437 *) stop=true
438 esac
439 done
440
441 if test $# -ne 4; then
442 usage
443 exit
444 fi
445
446 case "$1" in
447 iter) shift; bench_iteration $@ ;;
448 cct) shift; bench_concat $@ ;;
449 substr) shift; bench_substr $@ ;;
450 array) shift; bench_array $@ ;;
451 all) shift; benches $@ ;;
452 *) usage; exit;;
453 esac