5e8716bb2e7db19520eed4896f1c4fefb2a1a62e
[nit.git] / benchmarks / bench_engines.sh
1 #!/bin/bash
2 # This file is part of NIT ( http://www.nitlanguage.org ).
3 #
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
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16 # This shell script helps running benchmarks
17
18 # TODO: cleanup and libify the helper-parts
19
20 source ./bench_plot.sh
21
22 ## CONFIGURATION OPTIONS ##
23
24 # Default number of times a command must be run with bench_command
25 # Can be overrided with 'the option -n'
26 count=2
27
28 pep8analysis=../../pep8analysis
29
30 ### HELPER FUNCTIONS ##
31
32 function die()
33 {
34 echo >&2 "error: $*"
35 died=1
36 }
37
38 # Run a single command multiple time and store the execution times
39 # in the current $res file.
40 #
41 # $1: title of the command
42 # $2: long desription of the command
43 # rest: the command to execute
44 function bench_command()
45 {
46 if [ "$dry_run" = "true" ]; then return; fi
47 local title="$1"
48 local desc="$2"
49 shift
50 shift
51 if test "$verbose" = true; then outputopts="/dev/stdout"; else outputopts="/dev/null"; fi
52 timeout="time.out"
53 echo "$title" > "$timeout"
54 echo "# $desc" >> "$timeout"
55 echo "\$ $@" >> "$timeout"
56 echo
57 echo "** [$title] $desc **"
58 echo " $ $@"
59
60 # Execute the commands $count times
61 for i in `seq 1 "$count"`; do
62 /usr/bin/time -f "%U" -o "$timeout" -a "$@" > $outputopts 2>&1 || die "$1: failed"
63 echo -n "$i. "
64 tail -n 1 "$timeout"
65 done
66
67 line=`compute_stats "$timeout"`
68 echo "$line ($res)"
69 echo $line >> "$res"
70 }
71
72 # Run a simble command witout storing the execution time
73 # Used to display command on verbose and skip long executions when dry_run is given
74 # $@ command to execute
75 function run_command()
76 {
77 if [ "$dry_run" = "true" ]; then return; fi
78 echo " $ $@"
79 "$@" || die "$@: failed"
80 }
81
82 # Check if the test should be skiped according to its name
83 # $1: name of the test
84 # $2: description of the test
85 # $NOTSKIPED: arguments
86 function skip_test()
87 {
88 if test -z "$NOTSKIPED"; then
89 echo "* $1"
90 return 0
91 fi
92 if test "$NOTSKIPED" = "all"; then
93 : # Execute anyway
94 elif echo "$1" | egrep "$NOTSKIPED" >/dev/null 2>&1; then
95 : # Found one to execute
96 else
97 return 0
98 fi
99 echo "*"
100 echo "* $1 *****"
101 echo "*"
102 return 1
103 }
104
105 # HELPER FOR NIT #
106
107 # Run standards benchs on a compiler command
108 # $1: title
109 # rest: command to run (executable + options)
110 function run_compiler()
111 {
112 local title=$1
113 shift
114 if test -n "$fast"; then
115 run_command "$@" ../src/nitg.nit -o "nitg.$title.bin"
116 bench_command "nitg-g" "nitg --global ../src/test_parser.nit" "./nitg.$title.bin" -v --global --no-cc ../src/test_parser.nit
117 run_command "$@" ../src/nit.nit -o "nit.$title.bin"
118 bench_command "nit" "nit ../src/test_parser.nit ../src/location.nit" "./nit.$title.bin" -v ../src/test_parser.nit -- -n ../src/location.nit
119 run_command "$@" ../examples/shoot/shoot_logic.nit -o "shoot.$title.bin"
120 bench_command "shoot" "shoot_logic" "./shoot.$title.bin"
121 run_command "$@" ../tests/bench_bintree_gen.nit -o "bintrees.$title.bin"
122 bench_command "bintrees" "bench_bintree_gen 16" "./bintrees.$title.bin" 16
123 else
124 run_command "$@" ../src/nitg.nit -o "nitg.$title.bin"
125 bench_command "nitg-g" "nitg --global --no-cc ../src/nitmetrics.nit" "./nitg.$title.bin" -v --global --no-cc ../src/nitmetrics.nit
126 bench_command "nitg-s" "nitg --separate ../src/nitg.nit" "./nitg.$title.bin" -v --no-cc --separate ../src/nitg.nit
127 run_command "$@" ../src/nit.nit -o "nit.$title.bin"
128 bench_command "nit" "nit ../src/test_parser.nit ../src/rapid_type_analysis.nit" "./nit.$title.bin" -v ../src/test_parser.nit -- -n ../src/rapid_type_analysis.nit
129 run_command "$@" ../examples/shoot/shoot_logic.nit -o "shoot.$title.bin"
130 bench_command "shoot" "shoot_logic 30" "./shoot.$title.bin" 30
131 run_command "$@" ../tests/bench_bintree_gen.nit -o "bintrees.$title.bin"
132 bench_command "bintrees" "bench_bintree_gen 18" "./bintrees.$title.bin" 18
133 if test -f "$pep8analysis/src/pep8analysis.nit"; then
134 run_command "$@" "$pep8analysis/src/pep8analysis.nit" -I "$pep8analysis/lib" -o "pep8a.$title.bin"
135 bench_command "pep8analisis" "bench_bintree_gen 18" "./pep8a.$title.bin" "$pep8analysis/tests/privat/"*.pep
136 fi
137 fi
138 }
139
140 ## HANDLE OPTIONS ##
141
142 function usage()
143 {
144 echo "run_bench: [options]* benchname"
145 echo " -v: verbose mode"
146 echo " -n count: number of execution for each bar (default: $count)"
147 echo " --dry: Do not run the commands, just reuse the data and generate the graph"
148 echo " --fast: Run less and faster tests"
149 echo " -h: this help"
150 }
151
152 stop=false
153 while [ "$stop" = false ]; do
154 case "$1" in
155 -v) verbose=true; shift;;
156 -h) usage; exit;;
157 -n) count="$2"; shift; shift;;
158 --dry) dry_run=true; shift;;
159 --fast) fast=true; shift;;
160 *) stop=true
161 esac
162 done
163
164 NOTSKIPED="$*"
165
166 if test -z "$NOTSKIPED"; then
167 usage
168 echo "List of available benches:"
169 echo "* all: run all the benches"
170 fi
171
172 ## COMPILE ENGINES
173
174 test -f ../src/nitc_3 || ../src/ncall.sh -O
175 test -f ./nitg || ../src/nitc_3 ../src/nitg.nit -O -v
176
177 ## EFFECTIVE BENCHS ##
178
179 function bench_nitg_bootstrap()
180 {
181 name="$FUNCNAME"
182 skip_test "$name" && return
183 prepare_res "$name.dat" "" "Steps of the bootstrap of nitg by nitc"
184 rm nit?_nit*
185 cp ../src/nitc_3 ./nitc_nitc.bin
186 bench_command "c/c c" "nitc_nitc ../src/nitc.nit -> nitc_nitc (stability)" ./nitc_nitc.bin -O ../src/nitc.nit -o nitc_nitc.bin
187 bench_command "c/c g" "nitc_nitc ../src/nitg.nit -> nitg_nitc" ./nitc_nitc.bin -O ../src/nitg.nit -o nitg_nitc.bin
188 bench_command "g/c g" "nitg_nitc ../src/nitg.nit -> nitg_nitg" ./nitg_nitc.bin ../src/nitg.nit -o nitg_nitg.bin
189 bench_command "g/g g" "nitg_nitg ../src/nitg.nit -> nitg_nitg (stability)" ./nitg_nitg.bin ../src/nitg.nit -o nitg_nitg.bin
190
191 plot "$name.gnu"
192 }
193 bench_nitg_bootstrap
194
195 function bench_steps()
196 {
197 name="$FUNCNAME"
198 skip_test "$name" && return
199 prepare_res "$name-nitc.dat" "nitc" "Various steps of nitc"
200 bench_command "parse" "" ../src/nitc_3 --only-parse ../src/nitg.nit
201 bench_command "metamodel" "" ../src/nitc_3 --only-metamodel ../src/nitg.nit
202 bench_command "generate c" "" ../src/nitc_3 --no-cc ../src/nitg.nit
203 bench_command "full" "" ../src/nitc_3 -O ../src/nitg.nit -o "nitg_nitg.bin"
204
205 prepare_res "$name-nitc-g.dat" "nitc-g" "Various steps of nitc --global"
206 bench_command "parse" "" ../src/nitc_3 --global --only-parse ../src/nitg.nit
207 bench_command "metamodel" "" ../src/nitc_3 --global --only-metamodel ../src/nitg.nit
208 bench_command "generate c" "" ../src/nitc_3 --global --no-cc ../src/nitg.nit
209 bench_command "full" "" ../src/nitc_3 -O --global ../src/nitg.nit -o "nitg_nitc-g.bin"
210
211 prepare_res "$name-nitg.dat" "nitg-g" "Various steps of nitg --global"
212 bench_command "parse" "" ./nitg --global --only-parse ../src/nitg.nit
213 bench_command "metamodel" "" ./nitg --global --only-metamodel ../src/nitg.nit
214 bench_command "generate c" "" ./nitg --global --no-cc ../src/nitg.nit
215 bench_command "full" "" ./nitg --global ../src/nitg.nit -o "nitg_nitg.bin"
216
217 prepare_res "$name-nitg-s.dat" "nitg-s" "Various steps of nitg --separate"
218 bench_command "parse" "" ./nitg --separate --only-parse ../src/nitg.nit
219 bench_command "metamodel" "" ./nitg --separate --only-metamodel ../src/nitg.nit
220 bench_command "generate c" "" ./nitg --separate --no-cc ../src/nitg.nit
221 bench_command "full" "" ./nitg --separate ../src/nitg.nit -o "nitg_nitg-e.bin"
222
223 prepare_res "$name-nitg-e.dat" "nitg-e" "Various steps of nitg --erasure"
224 bench_command "parse" "" ./nitg --erasure --only-parse ../src/nitg.nit
225 bench_command "metamodel" "" ./nitg --erasure --only-metamodel ../src/nitg.nit
226 bench_command "generate c" "" ./nitg --erasure --no-cc ../src/nitg.nit
227 bench_command "full" "" ./nitg --erasure ../src/nitg.nit -o "nitg_nitg-e.bin"
228
229 plot "$name.gnu"
230 }
231 bench_steps
232
233 # $#: options to compare
234 function bench_nitg-g_options()
235 {
236 tag=$1
237 shift
238 name="$FUNCNAME-$tag"
239 skip_test "$name" && return
240 prepare_res "$name.dat" "no options" "nitg-g without options"
241 run_compiler "nitg-g" ./nitg --global
242
243 if test "$1" = NOALL; then
244 shift
245 elif test -n "$2"; then
246 prepare_res "$name-all.dat" "all" "nitg-g with all options $@"
247 run_compiler "nitg-g-$tag" ./nitg --global $@
248 fi
249
250 for opt in "$@"; do
251 prepare_res "$name$opt.dat" "$opt" "nitg-g with option $opt"
252 run_compiler "nitg-g$opt" ./nitg --global $opt
253 done
254
255 plot "$name.gnu"
256 }
257 bench_nitg-g_options "hardening" --hardening
258 bench_nitg-g_options "nocheck" --no-check-covariance --no-check-initialization --no-check-assert --no-check-autocast --no-check-other
259
260 function bench_nitg-s_options()
261 {
262 tag=$1
263 shift
264 name="$FUNCNAME-$tag"
265 skip_test "$name" && return
266 prepare_res "$name.dat" "no options" "nitg-s without options"
267 run_compiler "nitg-s" ./nitg --separate
268
269 if test "$1" = NOALL; then
270 shift
271 elif test -n "$2"; then
272 prepare_res "$name-all.dat" "all" "nitg-s with all options $@"
273 run_compiler "nitg-s-$tag" ./nitg --separate $@
274 fi
275
276 for opt in "$@"; do
277 prepare_res "$name$opt.dat" "$opt" "nitg-s with option $opt"
278 run_compiler "nitg-s$opt" ./nitg --separate $opt
279 done
280
281 plot "$name.gnu"
282 }
283 bench_nitg-s_options "slower" --hardening --no-inline-intern --no-union-attribute --no-shortcut-equal --no-shortcut-range
284 bench_nitg-s_options "nocheck" --no-check-covariance --no-check-initialization --no-check-assert --no-check-autocast --no-check-other
285 bench_nitg-s_options "faster" --inline-coloring-numbers
286 bench_nitg-s_options "typing" NOALL --bm-typing --phand-typing
287
288 function bench_nitg-e_options()
289 {
290 tag=$1
291 shift
292 name="$FUNCNAME-$tag"
293 skip_test "$name" && return
294 prepare_res "$name.dat" "no options" "nitg-e without options"
295 run_compiler "nitg-e" ./nitg --erasure
296
297 if test "$1" = NOALL; then
298 shift
299 elif test -n "$2"; then
300 prepare_res "$name-all.dat" "all" "nitg-e with all options $@"
301 run_compiler "nitg-e-$tag" ./nitg --erasure $@
302 fi
303
304 for opt in "$@"; do
305 prepare_res "$name$opt.dat" "$opt" "nitg-e with option $opt"
306 run_compiler "nitg-e$opt" ./nitg --erasure $opt
307 done
308
309 plot "$name.gnu"
310 }
311 bench_nitg-e_options "slower" --hardening --no-inline-intern --no-union-attribute --no-shortcut-equal --no-shortcut-range
312 bench_nitg-e_options "nocheck" --no-check-covariance --no-check-initialization --no-check-assert --no-check-autocast --no-check-other --no-check-erasure-cast
313 bench_nitg-e_options "faster" --inline-coloring-numbers
314 bench_nitg-e_options "typing" NOALL --bm-typing # --phand-typing
315
316 function bench_nitc_gc()
317 {
318 name="$FUNCNAME"
319 skip_test "$name" && return
320 for gc in nitgc boehm malloc large; do
321 prepare_res "$name-$gc.dat" "$gc" "nitc with gc=$gc"
322 export NIT_GC_OPTION="$gc"
323 run_compiler "nitc" ../src/nitc_3 -O
324 done
325
326 plot "$name.gnu"
327 }
328 bench_nitc_gc
329
330 function bench_nitc_boost()
331 {
332 name="$FUNCNAME"
333 skip_test "$name" && return
334 prepare_res "$name-slow.dat" "no -O" "nitc without -O"
335 run_compiler "nitc_slow" ../src/nitc_3
336 prepare_res "$name-fast.dat" "-O" "nitc with -O"
337 run_compiler "nitc" ../src/nitc_3 -O
338
339 plot "$name.gnu"
340 }
341 bench_nitc_boost
342
343 function bench_engines()
344 {
345 name="$FUNCNAME"
346 skip_test "$name" && return
347 prepare_res "$name-nitc.dat" "nitc" "nitc"
348 run_compiler "nitc" ../src/nitc_3 -O
349 prepare_res "$name-nitc-g.dat" "nitc-g" "nitc with --global"
350 run_compiler "nitc-g" ../src/nitc_3 -O --global
351 prepare_res "$name-nitg-g.dat" "nitg-g" "nitg with --global"
352 run_compiler "nitg-g" ./nitg --global
353 prepare_res "$name-nitg-s.dat" "nitg-s" "nitg with --separate"
354 run_compiler "nitg-s" ./nitg --separate
355 prepare_res "$name-nitg-e.dat" "nitg-e" "nitg with --erasure"
356 run_compiler "nitg-e" ./nitg --erasure
357 plot "$name.gnu"
358 }
359 bench_engines
360
361 function bench_nitc_vc_nitg-e()
362 {
363 name="$FUNCNAME"
364 skip_test "$name" && return
365 prepare_res "$name-nitc.dat" "nitc" "nitc"
366 run_compiler "nitc" ../src/nitc_3 -O
367 prepare_res "$name-nitc-malloc.dat" "nitc-malloc" "nitc with malloc"
368 NIT_GC_OPTION="malloc" run_compiler "nitc" ../src/nitc_3 -O
369 prepare_res "$name-nitc-bohem.dat" "nitc-boehm" "nitc with boehm"
370 NIT_GC_OPTION="boehm" run_compiler "nitc" ../src/nitc_3 -O
371 prepare_res "$name-nitg-e-nockeck-malloc.dat" "nitg-e-nc-malloc" "nitg with --erasure --no-check-autocast --no-check-erasure-cast and malloc"
372 NIT_GC_OPTION="malloc" run_compiler "nitg-e-nc-malloc" ./nitg --erasure --no-check-autocast --no-check-erasure-cast
373 prepare_res "$name-nitg-e-nockeck.dat" "nitg-e-nc" "nitg with --erasure --no-check-autocast --no-check-erasure-cast"
374 run_compiler "nitg-e-nc" ./nitg --erasure --no-check-autocast --no-check-erasure-cast
375 prepare_res "$name-nitg-e.dat" "nitg-e" "nitg with --erasure"
376 run_compiler "nitg-e" ./nitg --erasure
377 plot "$name.gnu"
378 }
379 bench_nitc_vc_nitg-e
380
381 function bench_nitg-e_gc()
382 {
383 name="$FUNCNAME"
384 skip_test "$name" && return
385 prepare_res "$name-nitg-e-malloc.dat" "nitg-e-malloc" "nitg with --erasure and malloc"
386 NIT_GC_OPTION="malloc" run_compiler "nitg-e-malloc" ./nitg --erasure
387 prepare_res "$name-nitg-e.dat" "nitg-e" "nitg with --erasure"
388 run_compiler "nitg-e" ./nitg --erasure
389 plot "$name.gnu"
390 }
391 bench_nitg-e_gc
392
393 function bench_cc_nitg-e()
394 {
395 name="$FUNCNAME"
396 skip_test "$name" && return
397 for o in "gcc0:CC=\"ccache gcc\" CFLAGS=-O0" "cl0:CC=\"ccache clang\" CFLAGS=-O0" "gccs:CC=\"ccache gcc\" CFLAGS=-Os" "cls:CC=\"ccache clang\" CFLAGS=-Os" "gcc2:CC=\"ccache gcc\" CFLAGS=-O2" "cl2:CC=\"ccache clang\" CFLAGS=-O2" "gcc3:CC=\"ccache gcc\" CFLAGS=-O3" "cl3:CC=\"ccache clang\" CFLAGS=-O3"; do
398 f=`echo "$o" | cut -f1 -d:`
399 o=`echo "$o" | cut -f2 -d:`
400 prepare_res "$name-nitg-e-$f.dat" "nitg-e-$f" "nitg with --erasure --make-flags $o"
401 run_compiler "nitg-e-$f" ./nitg --erasure --make-flags "$o"
402 done
403 plot "$name.gnu"
404 }
405 bench_cc_nitg-e
406
407 function bench_policy()
408 {
409 name="$FUNCNAME"
410 skip_test "$name" && return
411 prepare_res "$name-nitg-s.dat" "nitg-s" "nitg with --separate"
412 run_compiler "nitg-s" ./nitg --separate
413 prepare_res "$name-nitg-e.dat" "nitg-e" "nitg with --erasure"
414 run_compiler "nitg-e" ./nitg --erasure
415 prepare_res "$name-nitg-su.dat" "nitg-su" "nitg with --separate --no-check-covariance"
416 run_compiler "nitg-su" ./nitg --separate --no-check-covariance
417 prepare_res "$name-nitg-eu.dat" "nitg-eu" "nitg with --erasure --no-check-covariance --no-check-erasure-cast"
418 run_compiler "nitg-eu" ./nitg --erasure --no-check-covariance --no-check-erasure-cast
419 plot "$name.gnu"
420 }
421 bench_policy
422
423 function bench_compilation_time
424 {
425 name="$FUNCNAME"
426 skip_test "$name" && return
427 prepare_res "$name-nitc.dat" "nitc" "nitc"
428 for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitg.nit; do
429 bench_command `basename "$i" .nit` "" ../src/nitc_3 -O "$i" --no-cc
430 done
431 prepare_res "$name-nitg.dat" "nitg-g" "nitg --global"
432 for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitg.nit; do
433 bench_command `basename "$i" .nit` "" ./nitg --global "$i" --no-cc
434 done
435 prepare_res "$name-nitg-e.dat" "nitg-e" "nitg --separate"
436 for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitg.nit; do
437 bench_command `basename "$i" .nit` "" ./nitg --separate "$i" --no-cc
438 done
439 prepare_res "$name-nitg-e.dat" "nitg-e" "nitg --erasure"
440 for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitg.nit; do
441 bench_command `basename "$i" .nit` "" ./nitg --erasure "$i" --no-cc
442 done
443 plot "$name.gnu"
444 }
445 bench_compilation_time
446
447 if test -n "$died"; then
448 echo "Some commands failed"
449 exit 1
450 fi
451 exit 0