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'
32 echo "run_bench: [options]* bench_name args"
35 echo " -v: verbose mode"
36 echo " -n count: number of execution for each bar (default: $count)"
40 echo " index: indexed access benchmark"
41 echo " - usage : index loops strlen_min strlen_inc strlen_max"
42 echo " concat: string concatenation benchmark"
43 echo " - usage : concat loops strlen min_cct cct_inc max_cct"
44 echo " iteration: iteration benchmark"
45 echo " - usage : iteration loops strlen_min strlen_inc strlen_max"
46 echo " substring: substring benchmark"
47 echo " - usage : substring loops strlen_min strlen_inc strlen_max"
48 echo " compiler: compiler benchmark"
49 echo " - usage : compiler"
50 echo " basic : basic functionnality test of the variants on Hello World"
51 echo " - usage : basic"
54 function bench_index
()
57 echo "Wrong arguments for benchmark index."
61 echo "Generating executable index_bench for variant $variant"
62 ..
/..
/bin
/nitc
--global index_bench.nit
64 bench_indexed_variant
"string" $1 $2 $3 $4
65 bench_indexed_variant
"buffer" $1 $2 $3 $4
70 # $1: string or buffer
75 function bench_indexed_variant
()
78 prepare_res index_
$tmp.out
$tmp $tmp
79 for i
in `seq "$3" "$4" "$5"`; do
80 bench_command
$i index_
$tmp$i .
/index_bench
-m
$1 --loops
$2 --strlen
$i
84 function bench_concat
()
87 echo "Wrong arguments for benchmark concat."
92 echo "Generating executable chain_concat for variant $variant"
93 ..
/..
/bin
/nitc
--global chain_concat.nit
95 bench_concat_variant
"string" $1 $2 $3 $4 $5
96 bench_concat_variant
"buffer" $1 $2 $3 $4 $5
101 # $1: string or buffer
104 # $4: concatenations min
105 # $5: concatenations inc
106 # $6: concatenations max
107 function bench_concat_variant
()
110 prepare_res out
/concat
/concat_
$tmp.out
$tmp $tmp
111 for i
in `seq "$4" "$5" "$6"`; do
112 bench_command
$i $tmp$i .
/chain_concat
-m
$1 --loops
$2 --strlen
$3 --ccts
$i
116 function bench_iteration
()
118 if [ $# -lt
4 ]; then
119 echo "Wrong arguments for benchmark iteration."
123 echo "Generating executable iteration_bench for variant $variant"
124 ..
/..
/bin
/nitc
--global iteration_bench.nit
126 bench_iterate_variant
"iterator" "string" $1 $2 $3 $4
127 bench_iterate_variant
"index" "string" $1 $2 $3 $4
128 bench_iterate_variant
"iterator" "buffer" $1 $2 $3 $4
129 bench_iterate_variant
"index" "buffer" $1 $2 $3 $4
134 # $1: iterator or index
135 # $2: string or buffer
138 # $5: strlen increment
140 function bench_iterate_variant
()
142 tmp
="${variant}_$1_$2"
143 prepare_res out
/iteration
/iteration_
$tmp.out
$tmp $tmp
144 for i
in `seq "$4" "$5" "$6"`; do
145 bench_command
$i $tmp$i .
/iteration_bench
-m
$2 --iter
-mode
$1 --loops
$3 --strlen
$i
149 function bench_substring
()
151 if [ $# -lt
4 ]; then
152 echo "Wrong arguments for benchmark substring."
156 echo "Generating executable substr_bench for variant $variant"
157 ..
/..
/bin
/nitc
--global substr_bench.nit
159 bench_substring_variant
"string" $1 $2 $3 $4
160 bench_substring_variant
"buffer" $1 $2 $3 $4
165 # $1: string or buffer
168 # $4: strlen increment
170 function bench_substring_variant
()
173 prepare_res out
/substring
/substring_
$tmp.out
$tmp $tmp
174 for i
in `seq "$3" "$4" "$5"`; do
175 bench_command
$i $tmp$i .
/substr_bench
-m
$1 --loops
$2 --strlen
$i
179 function bench_compiler
()
181 prepare_res out
/compiler
/compiler_
$variant.out compiler_
$variant compiler_
$variant
183 echo "Pre-compiling nitc"
184 # Do it twice before bench to have stable times when generating C
185 ..
/..
/bin
/nitc ..
/..
/src
/nitc.nit
-o ..
/..
/bin
/nitc
187 ..
/..
/bin
/nitc ..
/..
/src
/nitc.nit
-o ..
/..
/bin
/nitc
190 bench_command nitc nitc_
$variant ..
/..
/bin
/nitc ..
/..
/src
/nitc.nit
195 function bench_basic
()
197 ..
/..
/bin
/nitc ..
/..
/examples
/hello_world.nit
202 function launch_bench
()
204 echo "---------------------------------------------------------"
205 echo " Trying variant $variant for benchmark $bench"
206 echo "---------------------------------------------------------"
207 git
diff-index
--quiet HEAD ||
{
208 echo "Cannot run benches on a dirty working directory."
209 echo "Please commit or stash your modifications and relaunch the command."
212 git am
$curr_rev ||
{
213 echo "Error when applying patch $curr_rev"
217 if [ "$need_bootstrap" = true
]; then
221 git
reset --hard
$head
224 function prepare_compiler
()
231 mv nitc.good ..
/bin
/nitc
232 cd ..
/benchmarks
/strings
238 while [ "$stop" = false
]; do
240 -v
) verbose
=true
; shift;;
242 -n
) count
="$2"; shift; shift;;
247 if [ $# -lt
1 ]; then
253 for i
in $benches; do
258 if [ "$isok" = false
]; then
266 git
diff-index
--quiet HEAD ||
{
267 echo "Cannot run benches on a dirty working directory."
268 echo "Please commit or stash your modifications and relaunch the command."
272 head=`git rev-parse HEAD`
277 if [ "$bench" = "basic" ]; then
281 if [ ! -d out
]; then
286 if [ -d
$bench ]; then
293 echo "---------------------------------------------------------"
294 echo " Trying variant HEAD for benchmark $bench"
295 echo "---------------------------------------------------------"
298 for i
in lib_variants
/regular
/*; do
300 variant
=`basename "$i" | cut -f 1 -d '.'`
305 for i
in lib_variants
/need_bootstrap
/*; do
307 variant
=`basename "$i" | cut -f 1 -d '.'`
311 if [ "${need_plot}" = true
]; then
312 plot out
/$bench/$bench.gnu