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"
48 function bench_concat
()
51 echo "*** Benching concat performance ***"
54 prepare_res concat_ropes.out concat_ropes ropes
58 for i
in `seq 1 "$1"`; do
60 echo "String length = $i, Concats/loop = $2, Loops = $3"
62 bench_command
$i ropes
$i .
/chain_concat
-m rope
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
65 prepare_res concat_flat.out concat_flat flatstring
69 for i
in `seq 1 "$1"`; do
71 echo "String length = $i, Concats/loop = $2, Loops = $3"
73 bench_command
$i flatstring
$i .
/chain_concat
-m flatstr
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
76 prepare_res concat_buf.out concat_buf flatbuffer
80 for i
in `seq 1 "$1"`; do
82 echo "String length = $i, Concats/loop = $2, Loops = $3"
84 bench_command
$i flatbuffer
$i .
/chain_concat
-m flatbuf
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
90 function bench_iteration
()
93 echo "*** Benching iteration performance ***"
96 prepare_res iter_ropes_iter.out iter_ropes_iter ropes_iter
98 echo "Ropes by iterator :"
100 for i
in `seq 1 "$1"`; do
102 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
104 bench_command
$i ropes_iter
$i .
/iteration_bench
-m rope
--iter
-mode iterator
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
107 prepare_res iter_ropes_index.out iter_ropes_index ropes_index
109 echo "Ropes by index :"
111 for i
in `seq 1 "$1"`; do
113 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
115 bench_command
$i ropes_index
$i .
/iteration_bench
-m rope
--iter
-mode index
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
118 prepare_res iter_flat_iter.out iter_flat_iter flatstring_iter
120 echo "FlatStrings by iterator :"
122 for i
in `seq 1 "$1"`; do
124 echo "String base length = $1, Concats = $i, Loops = $3"
126 bench_command
$i flatstr_iter
$i .
/iteration_bench
-m flatstr
--iter
-mode iterator
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
129 prepare_res iter_flat_index.out iter_flat_index flatstring_index
131 echo "FlatStrings by index :"
133 for i
in `seq 1 "$1"`; do
135 echo "String base length = $1, Concats = $i, Loops = $3"
137 bench_command
$i flatstr_index
$i .
/iteration_bench
-m flatstr
--iter
-mode index
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
140 prepare_res iter_buf_iter.out iter_buf_iter flatbuffer_iter
142 echo "FlatBuffers by iterator :"
144 for i
in `seq 1 "$1"`; do
146 echo "String base length = $1, Concats = $i, Loops = $3"
148 bench_command
$i flatbuf_iter
$i .
/iteration_bench
-m flatbuf
--iter
-mode iterator
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
151 prepare_res iter_buf_index.out iter_buf_index flatbuffer_index
153 echo "FlatBuffers by index:"
155 for i
in `seq 1 "$1"`; do
157 echo "String base length = $1, Concats = $i, Loops = $3"
159 bench_command
$i flatbuf_index
$i .
/iteration_bench
-m flatbuf
--iter
-mode index
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
165 function bench_substr
()
168 echo "*** Benching substring performance ***"
171 prepare_res substr_ropes.out substr_ropes ropes
175 for i
in `seq 1 "$1"`; do
177 echo "String length = $i, loops = $2, Loops = $3"
179 bench_command
$i ropes
$i .
/substr_bench
-m rope
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
182 prepare_res substr_flat.out substr_flat flatstring
186 for i
in `seq 1 "$1"`; do
188 echo "String length = $i, loops = $2, Loops = $3"
190 bench_command
$i flatstring
$i .
/substr_bench
-m flatstr
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
193 prepare_res substr_buf.out substr_buf flatbuffer
197 for i
in `seq 1 "$1"`; do
199 echo "String length = $i, loops = $2, Loops = $3"
201 bench_command
$i flatbuffer
$i .
/substr_bench
-m flatbuf
--loops
$2 --strlen
$3 --ccts
$i "NIT_GC_CHOOSER=large"
208 while [ "$stop" = false
]; do
210 -v
) verbose
=true
; shift;;
212 -n
) count
="$2"; shift; shift;;
217 if test $# -ne
4; then
226 ..
/bin
/nitg
--global .
/strings/chain_concat.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
227 ..
/bin
/nitg
--global .
/strings/iteration_bench.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
228 ..
/bin
/nitg
--global .
/strings/substr_bench.nit
--make-flags
"CFLAGS=\"-g -O2 -DNOBOEHM\""
231 iter
) shift; bench_iteration $@
;;
232 cct
) shift; bench_concat $@
;;
233 substr
) shift; bench_substr $@
;;
234 all
) shift; benches $@
;;