2 # This file is part of NIT ( http://www.nitlanguage.org ).
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 source .
/bench_common.sh
17 source .
/bench_plot.sh
19 # Default number of times a command must be run with bench_command
20 # Can be overrided with 'the option -n'
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)"
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"
51 function bench_array
()
54 echo "*** Benching Array.to_s performance ***"
57 ..
/bin
/nitg
--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\""
59 prepare_res arr_tos_ropes.out arr_tos_ropes ropes
63 for i
in `seq 1 "$3"`; do
65 echo "String length = $i, Concats/loop = $1, Loops = $2"
67 bench_command
$i ropes
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1 "NIT_GC_CHOOSER=large"
70 ..
/bin
/nitg
--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\""
72 prepare_res arr_tos_buf_ropes.out arr_tos_buf_ropes buffered_ropes
74 echo "Buffered Ropes :"
76 for i
in `seq 1 "$3"`; do
78 echo "String length = $i, Concats/loop = $1, Loops = $2"
80 bench_command
$i buf_ropes
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1 "NIT_GC_CHOOSER=large"
83 ..
/bin
/nitg
--global .
/strings/array_tos.nit
-m .
/strings/array_to_s_vars
/array_to_s_flatstr.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
85 prepare_res arr_tos_flat.out arr_tos_flat flatstring
89 for i
in `seq 1 "$3"`; do
91 echo "String length = $i, Concats/loop = $1, Loops = $2"
93 bench_command
$i flatstring
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1 "NIT_GC_CHOOSER=large"
96 ..
/bin
/nitg
--global .
/strings/array_tos.nit
-m .
/strings/array_to_s_vars
/array_to_s_buffer.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
98 prepare_res arr_tos_buf.out arr_tos_buf flatbuffer
102 for i
in `seq 1 "$3"`; do
104 echo "String length = $i, Concats/loop = $1, Loops = $2"
106 bench_command
$i flatbuffer
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1 "NIT_GC_CHOOSER=large"
109 ..
/bin
/nitg
--global .
/strings/array_tos.nit
-m .
/strings/array_to_s_vars
/array_to_s_manual.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
111 prepare_res arr_tos_man.out arr_tos_man memmove
115 for i
in `seq 1 "$3"`; do
117 echo "String length = $i, Concats/loop = $1, Loops = $2"
119 bench_command
$i memmove
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1 "NIT_GC_CHOOSER=large"
122 ..
/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\""
124 prepare_res arr_tos_man_buf.out arr_tos_man_buf flatbuf_with_capacity
126 echo "FlatBuffer.with_capacity :"
128 for i
in `seq 1 "$3"`; do
130 echo "String length = $i, Concats/loop = $1, Loops = $2"
132 bench_command
$i flatbuf_with_capacity
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1 "NIT_GC_CHOOSER=large"
135 ..
/bin
/nitg
--global .
/strings/array_tos.nit
-m .
/strings/array_to_s_vars
/array_to_s_rope_buf.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
137 prepare_res arr_tos_rope_buf.out arr_tos_rope_buf ropebuf
141 for i
in `seq 1 "$3"`; do
143 echo "String length = $i, Concats/loop = $1, Loops = $2"
145 bench_command
$i ropebuf
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1 "NIT_GC_CHOOSER=large"
151 function bench_concat
()
153 ..
/bin
/nitg
--global .
/strings/chain_concat.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
154 ..
/bin
/nitg
--global .
/strings/utf_chain_concat.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
157 echo "*** Benching concat performance ***"
160 prepare_res concat_flat.out concat_flat flatstring
164 for i
in `seq 1 "$1"`; do
166 echo "String length = $i, Concats/loop = $2, Loops = $3"
168 bench_command
$i flatstring
$i .
/chain_concat
-m flatstr
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
171 prepare_res concat_buf.out concat_buf flatbuffer
175 for i
in `seq 1 "$1"`; do
177 echo "String length = $i, Concats/loop = $2, Loops = $3"
179 bench_command
$i flatbuffer
$i .
/chain_concat
-m flatbuf
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
182 prepare_res concat_flatstr_utf8_noindex.out concat_flatstr_utf8_noindex flatstring_utf8_noindex
184 echo "FlatString UTF-8 (without index) :"
186 for i
in `seq 1 "$1"`; do
188 echo "String length = $i, Concats/loop = $2, Loops = $3"
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"
193 ..
/bin
/nitg
--global .
/strings/chain_concat.nit
-m ..
/lib
/standard
/ropes.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
195 prepare_res concat_ropes.out concat_ropes ropes
199 for i
in `seq 1 "$1"`; do
201 echo "String length = $i, Concats/loop = $2, Loops = $3"
203 bench_command
$i ropes
$i .
/chain_concat
-m flatstr
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
206 ..
/bin
/nitg
--global .
/strings/chain_concat.nit
-m ..
/lib
/standard
/ropes.nit
-m ..
/lib
/buffered_ropes.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
208 prepare_res concat_buf_ropes.out concat_buf_ropes buffered_ropes
210 echo "buffered ropes :"
212 for i
in `seq 1 "$1"`; do
214 echo "string length = $i, concats/loop = $2, loops = $3"
216 bench_command
$i buf_ropes
$i .
/chain_concat
-m flatstr
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
219 ..
/bin
/nitg
--global .
/strings/chain_cct_ropebuf.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
221 prepare_res cct_buf_ropes.out cct_buf_ropes cctbuf_ropes
223 echo "buffered ropes :"
225 for i
in `seq 1 "$1"`; do
227 echo "string length = $i, concats/loop = $2, loops = $3"
229 bench_command
$i cctbuf_ropes
$i .
/chain_cct_ropebuf
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
235 function bench_iteration
()
238 echo "*** Benching iteration performance ***"
241 ..
/bin
/nitg
--global .
/strings/iteration_bench.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
242 ..
/bin
/nitg
--global .
/strings/utf_iteration_bench.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
244 prepare_res iter_flat_iter.out iter_flat_iter flatstring_iter
246 echo "FlatStrings by iterator :"
248 for i
in `seq 1 "$1"`; do
250 echo "String base length = $1, Concats = $i, Loops = $3"
252 bench_command
$i flatstr_iter
$i .
/iteration_bench
-m flatstr
--iter
-mode iterator
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
255 prepare_res iter_flat_index.out iter_flat_index flatstring_index
257 echo "FlatStrings by index :"
259 for i
in `seq 1 "$1"`; do
261 echo "String base length = $1, Concats = $i, Loops = $3"
263 bench_command
$i flatstr_index
$i .
/iteration_bench
-m flatstr
--iter
-mode index
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
266 prepare_res iter_buf_iter.out iter_buf_iter flatbuffer_iter
268 echo "FlatBuffers by iterator :"
270 for i
in `seq 1 "$1"`; do
272 echo "String base length = $1, Concats = $i, Loops = $3"
274 bench_command
$i flatbuf_iter
$i .
/iteration_bench
-m flatbuf
--iter
-mode iterator
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
277 prepare_res iter_buf_index.out iter_buf_index flatbuffer_index
279 echo "FlatBuffers by index:"
281 for i
in `seq 1 "$1"`; do
283 echo "String base length = $1, Concats = $i, Loops = $3"
285 bench_command
$i flatbuf_index
$i .
/iteration_bench
-m flatbuf
--iter
-mode index
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
288 prepare_res iter_flat_utf8_noindex_iter.out iter_flat_iter_utf8_noindex flatstring_utf8_noindex_iter
290 echo "FlatStrings by iterator :"
292 for i
in `seq 1 "$1"`; do
294 echo "String base length = $1, Concats = $i, Loops = $3"
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"
299 prepare_res iter_flat_utf8_noindex_index.out iter_flat_index_utf8_noindex flatstring_utf8_noindex_index
301 echo "FlatStrings by index :"
303 for i
in `seq 1 "$1"`; do
305 echo "String base length = $1, Concats = $i, Loops = $3"
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"
310 ..
/bin
/nitg
--global .
/strings/iteration_bench.nit
-m ..
/lib
/standard
/ropes.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
312 prepare_res iter_ropes_iter.out iter_ropes_iter ropes_iter
314 echo "Ropes by iterator :"
316 for i
in `seq 1 "$1"`; do
318 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
320 bench_command
$i ropes_iter
$i .
/iteration_bench
-m flatstr
--iter
-mode iterator
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
323 prepare_res iter_ropes_index.out iter_ropes_index ropes_index
325 echo "Ropes by index :"
327 for i
in `seq 1 "$1"`; do
329 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
331 bench_command
$i ropes_index
$i .
/iteration_bench
-m flatstr
--iter
-mode index
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
334 ..
/bin
/nitg
--global .
/strings/iteration_bench.nit
-m ..
/lib
/standard
/ropes.nit
-m ..
/lib
/buffered_ropes.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
336 prepare_res iter_buf_ropes_iter.out iter_buf_ropes_iter buf_ropes_iter
338 echo "Buffered Ropes by iterator :"
340 for i
in `seq 1 "$1"`; do
342 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
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"
347 prepare_res iter_buf_ropes_index.out iter_buf_ropes_index buf_ropes_index
349 echo "Buffered Ropes by index :"
351 for i
in `seq 1 "$1"`; do
353 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
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"
361 function bench_substr
()
364 echo "*** Benching substring performance ***"
367 ..
/bin
/nitg
--global .
/strings/substr_bench.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
368 ..
/bin
/nitg
--global .
/strings/utf_substr_bench.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
370 prepare_res substr_flat.out substr_flat flatstring
374 for i
in `seq 1 "$1"`; do
376 echo "String length = $i, loops = $2, Loops = $3"
378 bench_command
$i flatstring
$i .
/substr_bench
-m flatstr
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
381 prepare_res substr_buf.out substr_buf flatbuffer
385 for i
in `seq 1 "$1"`; do
387 echo "String length = $i, loops = $2, Loops = $3"
389 bench_command
$i flatbuffer
$i .
/substr_bench
-m flatbuf
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
392 prepare_res substr_flat_utf8_noindex.out substr_flat_utf8_noindex flatstring_utf8_noindex
394 echo "FlatStrings UTF-8 (without index) :"
396 for i
in `seq 1 "$1"`; do
398 echo "String length = $i, loops = $2, Loops = $3"
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"
403 ..
/bin
/nitg
--global .
/strings/substr_bench.nit
-m ..
/lib
/standard
/ropes.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
405 prepare_res substr_ropes.out substr_ropes ropes
409 for i
in `seq 1 "$1"`; do
411 echo "String length = $i, loops = $2, Loops = $3"
413 bench_command
$i ropes
$i .
/substr_bench
-m flatstr
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
416 ..
/bin
/nitg
--global .
/strings/substr_bench.nit
-m ..
/lib
/standard
/ropes.nit
-m ..
/lib
/buffered_ropes.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
418 prepare_res substr_buf_ropes.out substr_buf_ropes buf_ropes
420 echo "Buffered Ropes :"
422 for i
in `seq 1 "$1"`; do
424 echo "String length = $i, loops = $2, Loops = $3"
426 bench_command
$i buf_ropes
$i .
/substr_bench
-m flatstr
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
432 while [ "$stop" = false
]; do
434 -v
) verbose
=true
; shift;;
436 -n
) count
="$2"; shift; shift;;
441 if test $# -ne
4; then
447 iter
) shift; bench_iteration $@
;;
448 cct
) shift; bench_concat $@
;;
449 substr
) shift; bench_substr $@
;;
450 array
) shift; bench_array $@
;;
451 all
) shift; benches $@
;;