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 " iter: bench iterations"
32 echo " - usage : iter max_nb_cct loops strlen"
33 echo " cct: concatenation benching"
34 echo " - usage : cct max_nb_cct loops strlen"
35 echo " substr: substring benching"
36 echo " - usage : substr max_nb_cct loops strlen"
37 echo " array: Benchmark for the to_s in array"
38 echo " - usage : array nb_cct loops max_arrlen"
41 function bench_array
()
43 if [ -d arraytos
]; then
51 echo "*** Benching Array.to_s performance ***"
54 ..
/..
/..
/bin
/nitc
--global ..
/array_tos.nit
-m ..
/array_to_s_vars
/array_to_s_rope.nit
56 prepare_res arr_tos_ropes.out arr_tos_ropes ropes
60 for i
in `seq 1 "$3"`; do
62 echo "String length = $i, Concats/loop = $1, Loops = $2"
64 bench_command
$i ropes
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1
67 ..
/..
/..
/bin
/nitc
--global ..
/array_tos.nit
-m ..
/array_to_s_vars
/array_to_s_flatstr.nit
69 prepare_res arr_tos_flat.out arr_tos_flat flatstring
73 for i
in `seq 1 "$3"`; do
75 echo "String length = $i, Concats/loop = $1, Loops = $2"
77 bench_command
$i flatstring
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1
80 ..
/..
/..
/bin
/nitc
--global ..
/array_tos.nit
-m ..
/array_to_s_vars
/array_to_s_buffer.nit
82 prepare_res arr_tos_buf.out arr_tos_buf flatbuffer
86 for i
in `seq 1 "$3"`; do
88 echo "String length = $i, Concats/loop = $1, Loops = $2"
90 bench_command
$i flatbuffer
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1
93 ..
/..
/..
/bin
/nitc
--global ..
/array_tos.nit
-m ..
/array_to_s_vars
/array_to_s_manual.nit
95 prepare_res arr_tos_man.out arr_tos_man memmove
99 for i
in `seq 1 "$3"`; do
101 echo "String length = $i, Concats/loop = $1, Loops = $2"
103 bench_command
$i memmove
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1
106 ..
/..
/..
/bin
/nitc
--global ..
/array_tos.nit
-m ..
/array_to_s_vars
/array_to_s_man_buf.nit
108 prepare_res arr_tos_man_buf.out arr_tos_man_buf flatbuf_with_capacity
110 echo "FlatBuffer.with_capacity :"
112 for i
in `seq 1 "$3"`; do
114 echo "String length = $i, Concats/loop = $1, Loops = $2"
116 bench_command
$i flatbuf_with_capacity
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1
119 ..
/..
/..
/bin
/nitc
--global ..
/array_tos.nit
-m ..
/array_to_s_vars
/array_to_s_rope_buf.nit
121 prepare_res arr_tos_rope_buf.out arr_tos_rope_buf ropebuf
125 for i
in `seq 1 "$3"`; do
127 echo "String length = $i, Concats/loop = $1, Loops = $2"
129 bench_command
$i ropebuf
$i .
/array_tos
--loops
$2 --strlen
$i --ccts
$1
137 function bench_concat
()
139 if [ -d string_concat
]; then
146 ..
/..
/..
/bin
/nitc
--global ..
/chain_concat.nit
149 echo "*** Benching concat performance ***"
152 prepare_res concat_flat.out concat_flat flatstring
156 for i
in `seq 1 "$1"`; do
158 echo "String length = $i, Concats/loop = $2, Loops = $3"
160 bench_command
$i flatstring
$i .
/chain_concat
-m flatstr
--loops
$2 --strlen
$3 --ccts
$i
163 prepare_res concat_buf.out concat_buf flatbuffer
167 for i
in `seq 1 "$1"`; do
169 echo "String length = $i, Concats/loop = $2, Loops = $3"
171 bench_command
$i flatbuffer
$i .
/chain_concat
-m flatbuf
--loops
$2 --strlen
$3 --ccts
$i
174 prepare_res concat_ropes.out concat_ropes ropes
178 for i
in `seq 1 "$1"`; do
180 echo "String length = $i, Concats/loop = $2, Loops = $3"
182 bench_command
$i ropes
$i .
/chain_concat
-m ropestr
--loops
$2 --strlen
$3 --ccts
$i
185 prepare_res concat_buf_ropes.out concat_buf_ropes buffered_ropes
189 for i
in `seq 1 "$1"`; do
191 echo "string length = $i, concats/loop = $2, loops = $3"
193 bench_command
$i buf_ropes
$i .
/chain_concat
-m ropebuf
--loops
$2 --strlen
$3 --ccts
$i
201 function bench_iteration
()
203 if [ -d string_iter
]; then
211 echo "*** Benching iteration performance ***"
214 ..
/..
/..
/bin
/nitc
--global ..
/iteration_bench.nit
216 prepare_res iter_flat_iter.out iter_flat_iter flatstring_iter
218 echo "FlatStrings by iterator :"
220 for i
in `seq 1 "$1"`; do
222 echo "String base length = $1, Concats = $i, Loops = $3"
224 bench_command
$i flatstr_iter
$i .
/iteration_bench
-m flatstr
--iter
-mode iterator
--loops
$2 --strlen
$3 --ccts
$i
227 prepare_res iter_flat_index.out iter_flat_index flatstring_index
229 echo "FlatStrings by index :"
231 for i
in `seq 1 "$1"`; do
233 echo "String base length = $1, Concats = $i, Loops = $3"
235 bench_command
$i flatstr_index
$i .
/iteration_bench
-m flatstr
--iter
-mode index
--loops
$2 --strlen
$3 --ccts
$i
238 prepare_res iter_buf_iter.out iter_buf_iter flatbuffer_iter
240 echo "FlatBuffers by iterator :"
242 for i
in `seq 1 "$1"`; do
244 echo "String base length = $1, Concats = $i, Loops = $3"
246 bench_command
$i flatbuf_iter
$i .
/iteration_bench
-m flatbuf
--iter
-mode iterator
--loops
$2 --strlen
$3 --ccts
$i
249 prepare_res iter_buf_index.out iter_buf_index flatbuffer_index
251 echo "FlatBuffers by index:"
253 for i
in `seq 1 "$1"`; do
255 echo "String base length = $1, Concats = $i, Loops = $3"
257 bench_command
$i flatbuf_index
$i .
/iteration_bench
-m flatbuf
--iter
-mode index
--loops
$2 --strlen
$3 --ccts
$i
260 prepare_res iter_ropes_iter.out iter_ropes_iter ropes_iter
262 echo "Ropes by iterator :"
264 for i
in `seq 1 "$1"`; do
266 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
268 bench_command
$i ropes_iter
$i .
/iteration_bench
-m ropestr
--iter
-mode iterator
--loops
$2 --strlen
$3 --ccts
$i
271 prepare_res iter_ropes_index.out iter_ropes_index ropes_index
273 echo "Ropes by index :"
275 for i
in `seq 1 "$1"`; do
277 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
279 bench_command
$i ropes_index
$i .
/iteration_bench
-m ropestr
--iter
-mode index
--loops
$2 --strlen
$3 --ccts
$i
282 prepare_res iter_buf_ropes_iter.out iter_buf_ropes_iter buf_ropes_iter
284 echo "RopeBuffer by iterator :"
286 for i
in `seq 1 "$1"`; do
288 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
290 bench_command
$i buf_ropes_iter
$i .
/iteration_bench
-m ropebuf
--iter
-mode iterator
--loops
$2 --strlen
$3 --ccts
$i
293 prepare_res iter_buf_ropes_index.out iter_buf_ropes_index buf_ropes_index
295 echo "RopeBuffer by index :"
297 for i
in `seq 1 "$1"`; do
299 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
301 bench_command
$i buf_ropes_index
$i .
/iteration_bench
-m ropebuf
--iter
-mode index
--loops
$2 --strlen
$3 --ccts
$i
309 function bench_substr
()
311 if [ -d string_substr
]; then
319 echo "*** Benching substring performance ***"
322 ..
/..
/..
/bin
/nitc
--global ..
/substr_bench.nit
324 prepare_res substr_flat.out substr_flat flatstring
328 for i
in `seq 1 "$1"`; do
330 echo "String length = $i, loops = $2, Loops = $3"
332 bench_command
$i flatstring
$i .
/substr_bench
-m flatstr
--loops
$2 --strlen
$3 --ccts
$i
335 prepare_res substr_buf.out substr_buf flatbuffer
339 for i
in `seq 1 "$1"`; do
341 echo "String length = $i, loops = $2, Loops = $3"
343 bench_command
$i flatbuffer
$i .
/substr_bench
-m flatbuf
--loops
$2 --strlen
$3 --ccts
$i
346 prepare_res substr_ropes.out substr_ropes ropes
350 for i
in `seq 1 "$1"`; do
352 echo "String length = $i, loops = $2, Loops = $3"
354 bench_command
$i ropes
$i .
/substr_bench
-m ropestr
--loops
$2 --strlen
$3 --ccts
$i
357 prepare_res substr_buf_ropes.out substr_buf_ropes buf_ropes
361 for i
in `seq 1 "$1"`; do
363 echo "String length = $i, loops = $2, Loops = $3"
365 bench_command
$i buf_ropes
$i .
/substr_bench
-m ropebuf
--loops
$2 --strlen
$3 --ccts
$i
374 while [ "$stop" = false
]; do
376 -v
) verbose
=true
; shift;;
378 -n
) count
="$2"; shift; shift;;
383 if test $# -ne
4; then
389 iter
) shift; bench_iteration $@
;;
390 cct
) shift; bench_concat $@
;;
391 substr
) shift; bench_substr $@
;;
392 array
) shift; bench_array $@
;;