update NOTICE
[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_common.sh
21 source ./bench_plot.sh
22
23 ## CONFIGURATION OPTIONS ##
24
25 # Default number of times a command must be run with bench_command
26 # Can be overrided with 'the option -n'
27 count=2
28
29 ### HELPER FUNCTIONS ##
30
31 function die()
32 {
33 echo >&2 "error: $*"
34 died=1
35 }
36
37 # HELPER FOR NIT #
38
39 # Run standards benchs on a compiler command
40 # $1: title
41 # rest: command to run (executable + options)
42 function run_compiler()
43 {
44 local title=$1
45 shift
46 if test -n "$fast"; then
47 run_command "$@" ../src/nitc.nit -o "nitc.$title.bin"
48 bench_command "nitc-g" "nitc --global ../src/test_parser.nit" "./nitc.$title.bin" -v --global --no-cc ../src/test_parser.nit
49 run_command "$@" ../src/nit.nit -o "nit.$title.bin"
50 bench_command "nit" "nit ../src/test_parser.nit ../src/location.nit" "./nit.$title.bin" -v ../src/test_parser.nit -- -n ../src/location.nit
51 run_command "$@" ../examples/shoot/src/shoot_logic.nit -o "shoot.$title.bin"
52 bench_command "shoot" "shoot_logic" "./shoot.$title.bin"
53 run_command "$@" ../tests/bench_bintree_gen.nit -o "bintrees.$title.bin"
54 bench_command "bintrees" "bench_bintree_gen 16" "./bintrees.$title.bin" 16
55 else
56 run_command "$@" ../src/nitc.nit -o "nitc.$title.bin"
57 bench_command "nitc-g" "nitc --global --no-cc ../src/nitls.nit" "./nitc.$title.bin" -v --global --no-cc ../src/nitls.nit
58 bench_command "nitc-s" "nitc --separate ../src/nitc.nit" "./nitc.$title.bin" -v --no-cc --separate ../src/nitc.nit
59 run_command "$@" ../src/nit.nit -o "nit.$title.bin"
60 bench_command "nit" "nit ../src/test_parser.nit ../src/nitls.nit" "./nit.$title.bin" -v ../src/test_parser.nit -- -n ../src/nitls.nit
61 run_command "$@" ../src/nitdoc.nit -o "nitdoc.$title.bin"
62 rm -r out 2> /dev/null
63 mkdir out 2> /dev/null
64 bench_command "nitdoc" "nitdoc ../src/nitls.nit" "./nitdoc.$title.bin" -v ../src/nitls.nit -d out
65 run_command "$@" ../examples/shoot/src/shoot_logic.nit -o "shoot.$title.bin"
66 bench_command "shoot" "shoot_logic 15" "./shoot.$title.bin" 15
67 run_command "$@" ../tests/bench_bintree_gen.nit -o "bintrees.$title.bin"
68 bench_command "bintrees" "bench_bintree_gen 17" "./bintrees.$title.bin" 17
69 #run_command "$@" "../contrib/pep8analysis/src/pep8analysis.nit" -o "pep8a.$title.bin"
70 #bench_command "pep8analisis" "bench_pep8analisis" "./pep8a.$title.bin" "../contrib/pep8analysis/tests/privat/"*.pep
71 run_command "$@" "../lib/ai/examples/queens.nit" -o "queens.$title.bin"
72 bench_command "queens" "bench_queens 13" "./queens.$title.bin" 13
73 run_command "$@" "../lib/ai/examples/puzzle.nit" -o "puzzle.$title.bin"
74 bench_command "puzzle" "puzzle 15-hard" "./puzzle.$title.bin" kleg.mondcafjhbi
75 fi
76
77 rm -r *.bin .nit_compile out
78 }
79
80 ## HANDLE OPTIONS ##
81
82 function usage()
83 {
84 echo "run_bench: [options]* benchname"
85 echo " -v: verbose mode"
86 echo " -n count: number of execution for each bar (default: $count)"
87 echo " --dry: Do not run the commands, just reuse the data and generate the graph"
88 echo " --fast: Run less and faster tests"
89 echo " --html: Generate and HTML output"
90 echo " -h: this help"
91 }
92
93 stop=false
94 while [ "$stop" = false ]; do
95 case "$1" in
96 -v) verbose=true; shift;;
97 -h) usage; exit;;
98 -n) count="$2"; shift; shift;;
99 --dry) dry_run=true; shift;;
100 --fast) fast=true; shift;;
101 --html) html="index.html"; echo >"$html" "<html><head></head><body>"; shift;;
102 *) stop=true
103 esac
104 done
105
106 xml="bench_engines.xml"
107 echo "<testsuites><testsuite>" > "$xml"
108
109 NOTSKIPED="$*"
110
111 if test -z "$NOTSKIPED"; then
112 usage
113 echo "List of available benches:"
114 echo "* all: run all the benches"
115 fi
116
117 ## COMPILE ENGINES
118
119 # get the bootstrapped nitc
120 cp ../bin/nitc .
121
122 ## EFFECTIVE BENCHS ##
123
124 function bench_steps()
125 {
126 name="$FUNCNAME"
127 skip_test "$name" && return
128 prepare_res "$name-nitc.dat" "nitc-g" "Various steps of nitc --global"
129 bench_command "parse" "" ./nitc --global --only-parse ../src/nitc.nit
130 bench_command "metamodel" "" ./nitc --global --only-metamodel ../src/nitc.nit
131 bench_command "generate c" "" ./nitc --global --no-cc ../src/nitc.nit
132 bench_command "full" "" ./nitc --global ../src/nitc.nit -o "nitc_nitc.bin"
133
134 prepare_res "$name-nitc-s.dat" "nitc-s" "Various steps of nitc --separate"
135 bench_command "parse" "" ./nitc --separate --only-parse ../src/nitc.nit
136 bench_command "metamodel" "" ./nitc --separate --only-metamodel ../src/nitc.nit
137 bench_command "generate c" "" ./nitc --separate --no-cc ../src/nitc.nit
138 bench_command "full" "" ./nitc --separate ../src/nitc.nit -o "nitc_nitc-e.bin"
139
140 prepare_res "$name-nitc-e.dat" "nitc-e" "Various steps of nitc --erasure"
141 bench_command "parse" "" ./nitc --erasure --only-parse ../src/nitc.nit
142 bench_command "metamodel" "" ./nitc --erasure --only-metamodel ../src/nitc.nit
143 bench_command "generate c" "" ./nitc --erasure --no-cc ../src/nitc.nit
144 bench_command "full" "" ./nitc --erasure ../src/nitc.nit -o "nitc_nitc-e.bin"
145
146 plot "$name.gnu"
147 }
148 bench_steps
149
150 # $#: options to compare
151 function bench_nitc-g_options()
152 {
153 tag=$1
154 shift
155 name="$FUNCNAME-$tag"
156 skip_test "$name" && return
157 prepare_res "$name.dat" "no options" "nitc-g without options"
158 run_compiler "nitc-g" ./nitc --global
159
160 if test "$1" = NOALL; then
161 shift
162 elif test -n "$2"; then
163 prepare_res "$name-all.dat" "all" "nitc-g with all options $@"
164 run_compiler "nitc-g-$tag" ./nitc --global $@
165 fi
166
167 for opt in "$@"; do
168 ot=${opt// /+}
169 prepare_res "$name$ot.dat" "$opt" "nitc-g with option $opt"
170 run_compiler "nitc-g$ot" ./nitc --global $opt
171 done
172
173 plot "$name.gnu"
174 }
175 bench_nitc-g_options "slower" --hardening --no-shortcut-range
176 bench_nitc-g_options "nocheck" --no-check-null --no-check-autocast --no-check-attr-isset --no-check-covariance --no-check-assert
177
178 function bench_nitc-s_options()
179 {
180 tag=$1
181 shift
182 name="$FUNCNAME-$tag"
183 skip_test "$name" && return
184 prepare_res "$name.dat" "no options" "nitc-s without options"
185 run_compiler "nitc-s" ./nitc --separate
186
187 if test "$1" = NOALL; then
188 shift
189 elif test -n "$2"; then
190 prepare_res "$name-all.dat" "all" "nitc-s with all options $@"
191 run_compiler "nitc-s-$tag" ./nitc --separate $@
192 fi
193
194 for opt in "$@"; do
195 ot=${opt// /+}
196 prepare_res "$name-$ot.dat" "$opt" "nitc-s with option $opt"
197 run_compiler "nitc-s$ot" ./nitc --separate $opt
198 done
199
200 plot "$name.gnu"
201 }
202 bench_nitc-s_options "slower" --hardening --no-shortcut-equal --no-union-attribute --no-shortcut-range --no-inline-intern "--no-gcc-directive likely --no-gcc-directive noreturn"
203 bench_nitc-s_options "nocheck" --no-check-null --no-check-autocast --no-check-attr-isset --no-check-covariance --no-check-assert
204 bench_nitc-s_options "faster" --skip-dead-methods --inline-coloring-numbers --inline-some-methods --direct-call-monomorph "--inline-some-methods --direct-call-monomorph" ""
205
206 function bench_nitc-e_options()
207 {
208 tag=$1
209 shift
210 name="$FUNCNAME-$tag"
211 skip_test "$name" && return
212 prepare_res "$name.dat" "no options" "nitc-e without options"
213 run_compiler "nitc-e" ./nitc --erasure
214
215 if test "$1" = NOALL; then
216 shift
217 elif test -n "$2"; then
218 prepare_res "$name-all.dat" "all" "nitc-e with all options $@"
219 run_compiler "nitc-e-$tag" ./nitc --erasure $@
220 fi
221
222 for opt in "$@"; do
223 ot=${opt// /+}
224 prepare_res "$name$ot.dat" "$opt" "nitc-e with option $opt"
225 run_compiler "nitc-e$ot" ./nitc --erasure $opt
226 done
227
228 plot "$name.gnu"
229 }
230 bench_nitc-e_options "slower" --hardening --no-shortcut-equal --no-union-attribute --no-shortcut-range --no-inline-intern
231 bench_nitc-e_options "nocheck" --no-check-null --no-check-autocast --no-check-attr-isset --no-check-covariance --no-check-assert --no-check-erasure-cast
232 bench_nitc-e_options "faster" --skip-dead-methods --inline-coloring-numbers --inline-some-methods --direct-call-monomorph --rta
233
234 function bench_engines()
235 {
236 name="$FUNCNAME"
237 skip_test "$name" && return
238 prepare_res "$name-nitc-s.dat" "nitc-s" "nitc with --separate"
239 run_compiler "nitc-s" ./nitc --separate
240 prepare_res "$name-nitc-e.dat" "nitc-e" "nitc with --erasure"
241 run_compiler "nitc-e" ./nitc --erasure
242 prepare_res "$name-nitc-sg.dat" "nitc-sg" "nitc with --separate --semi-global"
243 run_compiler "nitc-sg" ./nitc --separate --semi-global
244 prepare_res "$name-nitc-eg.dat" "nitc-eg" "nitc with --erasure --semi-global"
245 run_compiler "nitc-eg" ./nitc --erasure --semi-global
246 prepare_res "$name-nitc-egt.dat" "nitc-egt" "nitc with --erasure --semi-global --rta"
247 run_compiler "nitc-egt" ./nitc --erasure --semi-global --rta
248 prepare_res "$name-nitc-g.dat" "nitc-g" "nitc with --global"
249 run_compiler "nitc-g" ./nitc --global
250 plot "$name.gnu"
251 }
252 bench_engines
253
254 function bench_nitc-e_gc()
255 {
256 name="$FUNCNAME"
257 skip_test "$name" && return
258 prepare_res "$name-nitc-e.dat" "nitc-e" "nitc with --erasure"
259 run_compiler "nitc-e" ./nitc --erasure
260 prepare_res "$name-nitc-e-malloc.dat" "nitc-e-malloc" "nitc with --erasure and malloc"
261 NIT_GC_OPTION="malloc" run_compiler "nitc-e-malloc" ./nitc --erasure
262 prepare_res "$name-nitc-e-large.dat" "nitc-e-large" "nitc with --erasure and large"
263 NIT_GC_OPTION="large" run_compiler "nitc-e-large" ./nitc --erasure
264 plot "$name.gnu"
265 }
266 bench_nitc-e_gc
267
268 function bench_cc_nitc-e()
269 {
270 name="$FUNCNAME"
271 skip_test "$name" && return
272 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
273 f=`echo "$o" | cut -f1 -d:`
274 o=`echo "$o" | cut -f2 -d:`
275 prepare_res "$name-nitc-e-$f.dat" "nitc-e-$f" "nitc with --erasure --make-flags $o"
276 run_compiler "nitc-e-$f" ./nitc --erasure --make-flags "$o"
277 done
278 plot "$name.gnu"
279 }
280 bench_cc_nitc-e
281
282 function bench_policy()
283 {
284 name="$FUNCNAME"
285 skip_test "$name" && return
286 prepare_res "$name-nitc-s.dat" "nitc-s" "nitc with --separate"
287 run_compiler "nitc-s" ./nitc --separate
288 prepare_res "$name-nitc-e.dat" "nitc-e" "nitc with --erasure"
289 run_compiler "nitc-e" ./nitc --erasure
290 prepare_res "$name-nitc-su.dat" "nitc-su" "nitc with --separate --no-check-covariance"
291 run_compiler "nitc-su" ./nitc --separate --no-check-covariance
292 prepare_res "$name-nitc-eu.dat" "nitc-eu" "nitc with --erasure --no-check-covariance --no-check-erasure-cast"
293 run_compiler "nitc-eu" ./nitc --erasure --no-check-covariance --no-check-erasure-cast
294 plot "$name.gnu"
295 }
296 bench_policy
297
298 function bench_nullables()
299 {
300 name="$FUNCNAME"
301 skip_test "$name" && return
302 prepare_res "$name-nitc.dat" "nitc" "nitc no options"
303 run_compiler "nitc" ./nitc --separate
304 prepare_res "$name-nitc-ni.dat" "nitc-ni" "nitc --no-check-attr-isset"
305 run_compiler "nitc" ./nitc --separate --no-check-attr-isset
306 prepare_res "$name-nitc-nu.dat" "nitc-nu" "nitc --no-union-attribute"
307 run_compiler "nitc" ./nitc --separate --no-union-attribute
308 prepare_res "$name-nitc-nu-ni.dat" "nitc-nu-ni" "nitc --no-union-attribute --no-check-attr-isset"
309 run_compiler "nitc" ./nitc --separate --no-union-attribute --no-check-attr-isset
310 plot "$name.gnu"
311 }
312 bench_nullables
313
314 function bench_compilation_time
315 {
316 name="$FUNCNAME"
317 skip_test "$name" && return
318 prepare_res "$name-nitc-g.dat" "nitc-g" "nitc --global"
319 for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitc.nit; do
320 bench_command `basename "$i" .nit` "" ./nitc --global "$i" --no-cc
321 done
322 prepare_res "$name-nitc-s.dat" "nitc-s" "nitc --separate"
323 for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitc.nit; do
324 bench_command `basename "$i" .nit` "" ./nitc --separate "$i" --no-cc
325 done
326 prepare_res "$name-nitc-e.dat" "nitc-e" "nitc --erasure"
327 for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitc.nit; do
328 bench_command `basename "$i" .nit` "" ./nitc --erasure "$i" --no-cc
329 done
330 plot "$name.gnu"
331 }
332 bench_compilation_time
333
334 if test -n "$html"; then
335 echo >>"$html" "</body></html>"
336 fi
337
338 echo >>"$xml" "</testsuite></testsuites>"
339
340 if test -n "$died"; then
341 echo "Some commands failed"
342 exit 1
343 fi
344 exit 0