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)"
38 echo " --head-only: do not try to pass benchmarks on variants"
39 echo " --maxlen min_maxln inc_maxln max_maxln: start bench with different values of threshold between ropes and flats"
42 echo " index: indexed access benchmark"
43 echo " - usage : index loops strlen_min strlen_inc strlen_max"
44 echo " concat: string concatenation benchmark"
45 echo " - usage : concat loops strlen min_cct cct_inc max_cct"
46 echo " iteration: iteration benchmark"
47 echo " - usage : iteration loops strlen_min strlen_inc strlen_max"
48 echo " substring: substring benchmark"
49 echo " - usage : substring loops strlen_min strlen_inc strlen_max"
50 echo " compiler: compiler benchmark"
51 echo " - usage : compiler"
52 echo " basic : basic functionnality test of the variants on Hello World"
53 echo " - usage : basic"
56 function bench_index
()
59 echo "Wrong arguments for benchmark index."
63 echo "Generating executable index_bench for variant $variant";
65 ..
/..
/bin
/nitc
--global index_bench.nit
-D maxlen
=$curr_maxln
67 bench_indexed_variant
"string" $1 $2 $3 $4
68 bench_indexed_variant
"buffer" $1 $2 $3 $4
73 # $1: string or buffer
78 function bench_indexed_variant
()
80 tmp
="${variant}_${1}_${curr_maxln}.out"
81 prepare_res_lines index_
$tmp $tmp $tmp
82 for i
in `seq "$3" "$4" "$5"`; do
83 bench_command
$i index_
$tmp$i .
/index_bench
-m
$1 --loops
$2 --strlen
$i
87 function bench_concat
()
90 echo "Wrong arguments for benchmark concat."
95 echo "Generating executable chain_concat for variant $variant"
96 ..
/..
/bin
/nitc chain_concat.nit
-D maxlen
=$curr_maxlen
98 bench_concat_variant
"string" $1 $2 $3 $4 $5
99 bench_concat_variant
"buffer" $1 $2 $3 $4 $5
104 # $1: string or buffer
107 # $4: concatenations min
108 # $5: concatenations inc
109 # $6: concatenations max
110 function bench_concat_variant
()
113 prepare_res_lines out
/concat
/concat_
$tmp.out
$tmp $tmp
114 for i
in `seq "$4" "$5" "$6"`; do
115 bench_command
$i $tmp$i .
/chain_concat
-m
$1 --loops
$2 --strlen
$3 --ccts
$i
119 function bench_iteration
()
121 if [ $# -lt
4 ]; then
122 echo "Wrong arguments for benchmark iteration."
126 echo "Generating executable iteration_bench for variant $variant"
127 ..
/..
/bin
/nitc
--global iteration_bench.nit
-D maxlen
=$curr_maxlen
129 bench_iterate_variant
"iterator" "string" $1 $2 $3 $4
130 bench_iterate_variant
"index" "string" $1 $2 $3 $4
131 bench_iterate_variant
"iterator" "buffer" $1 $2 $3 $4
132 bench_iterate_variant
"index" "buffer" $1 $2 $3 $4
137 # $1: iterator or index
138 # $2: string or buffer
141 # $5: strlen increment
143 function bench_iterate_variant
()
145 tmp
="${variant}_$1_$2"
146 prepare_res_lines out
/iteration
/iteration_
$tmp.out
$tmp $tmp
147 for i
in `seq "$4" "$5" "$6"`; do
148 bench_command
$i $tmp$i .
/iteration_bench
-m
$2 --iter
-mode
$1 --loops
$3 --strlen
$i
152 function bench_substring
()
154 if [ $# -lt
4 ]; then
155 echo "Wrong arguments for benchmark substring."
159 echo "Generating executable substr_bench for variant $variant"
160 ..
/..
/bin
/nitc
--global substr_bench.nit
-D maxlen
=$curr_maxlen
162 bench_substring_variant
"string" $1 $2 $3 $4
163 bench_substring_variant
"buffer" $1 $2 $3 $4
168 # $1: string or buffer
171 # $4: strlen increment
173 function bench_substring_variant
()
176 prepare_res_lines out
/substring
/substring_
$tmp.out
$tmp $tmp
177 for i
in `seq "$3" "$4" "$5"`; do
178 bench_command
$i $tmp$i .
/substr_bench
-m
$1 --loops
$2 --strlen
$i
182 function bench_compiler
()
184 prepare_res_lines out
/compiler
/compiler_
$variant.out compiler_
$variant compiler_
$variant
186 echo "Pre-compiling nitc"
187 # Do it twice before bench to have stable times when generating C
188 ..
/..
/bin
/nitc ..
/..
/src
/nitc.nit
-o ..
/..
/bin
/nitc
190 ..
/..
/bin
/nitc ..
/..
/src
/nitc.nit
-o ..
/..
/bin
/nitc
193 bench_command nitc nitc_
$variant ..
/..
/bin
/nitc ..
/..
/src
/nitc.nit
-D maxlen
=$curr_maxlen
198 function bench_basic
()
200 ..
/..
/bin
/nitc ..
/..
/examples
/hello_world.nit
-D maxlen
=$curr_maxlen
205 function launch_bench
()
207 echo "---------------------------------------------------------"
208 echo " Trying variant $variant for benchmark $bench"
209 echo "---------------------------------------------------------"
210 git
diff-index
--quiet HEAD ||
{
211 die
"Cannot run benches on a dirty working directory."
212 die
"Please commit or stash your modifications and relaunch the command."
215 git am
$curr_rev ||
{
216 die
"Error when applying patch $curr_rev"
220 if [ "$need_bootstrap" = true
]; then
224 git
reset --hard
$head
227 function prepare_compiler
()
234 mv nitc.good ..
/bin
/nitc
235 cd ..
/benchmarks
/strings
244 echo >"$html" "<html><head></head><body>"
246 while [ "$stop" = false
]; do
248 --maxlen
) bench_maxln
=true
; min_maxln
=$2; inc_maxln
=$3; max_maxln
=$4; shift; shift; shift; shift;;
249 -v
) verbose
=true
; shift;;
251 -n
) count
="$2"; shift; shift;;
252 --head-only
) head_only
=true
; shift;;
257 if [ $# -lt
1 ]; then
263 for i
in $benches; do
268 if [ "$isok" = false
]; then
276 if [ "${bench_maxln}" = true
]; then
277 for i
in `seq $min_maxln $inc_maxln $max_maxln`; do curr_maxln
=$i; launch_benches
"$@"; done;
282 if [ "${need_plot}" = true
]; then
283 plot_lines out
/$bench/$bench.gnu
286 echo >> "$html" "</body></html>"
289 function launch_benches
()
291 head=`git rev-parse HEAD`
296 if [ "$bench" = "basic" ]; then
300 if [ ! -d out
]; then
305 if [ -d
$bench ]; then
312 echo "---------------------------------------------------------"
313 echo " Trying variant HEAD for benchmark $bench"
314 echo "---------------------------------------------------------"
317 if [ ! $head_only ]; then
318 for i
in lib_variants
/regular
/*; do
320 variant
=`basename "$i" | cut -f 1 -d '.'`
325 for i
in lib_variants
/need_bootstrap
/*; do
327 variant
=`basename "$i" | cut -f 1 -d '.'`
335 if test -n
"$died"; then
336 echo "Some commands failed"