benches: add markdown as a task in bench_engines
[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 run_command "$@" "markdown/engines/nitmd/nitmd.nit" -o "nitmd.$title.bin"
76 bench_command "nitmd" "markdown" "./nitmd.$title.bin" markdown/benches/out/mixed.md 80
77 fi
78
79 rm -r *.bin .nit_compile out
80 }
81
82 ## HANDLE OPTIONS ##
83
84 function usage()
85 {
86 echo "run_bench: [options]* benchname"
87 echo " -v: verbose mode"
88 echo " -n count: number of execution for each bar (default: $count)"
89 echo " --dry: Do not run the commands, just reuse the data and generate the graph"
90 echo " --fast: Run less and faster tests"
91 echo " --html: Generate and HTML output"
92 echo " -h: this help"
93 }
94
95 stop=false
96 while [ "$stop" = false ]; do
97 case "$1" in
98 -v) verbose=true; shift;;
99 -h) usage; exit;;
100 -n) count="$2"; shift; shift;;
101 --dry) dry_run=true; shift;;
102 --fast) fast=true; shift;;
103 --html) html="index.html"; echo >"$html" "<html><head></head><body>"; shift;;
104 *) stop=true
105 esac
106 done
107
108 xml="bench_engines.xml"
109 echo "<testsuites><testsuite>" > "$xml"
110
111 NOTSKIPED="$*"
112
113 if test -z "$NOTSKIPED"; then
114 usage
115 echo "List of available benches:"
116 echo "* all: run all the benches"
117 fi
118
119 ## COMPILE ENGINES
120
121 # get the bootstrapped nitc
122 cp ../bin/nitc .
123
124 if test -z "$fast"; then
125 make -C markdown/benches
126 fi
127
128 ## EFFECTIVE BENCHS ##
129
130 function bench_steps()
131 {
132 name="$FUNCNAME"
133 skip_test "$name" && return
134 prepare_res "$name-nitc.dat" "nitc-g" "Various steps of nitc --global"
135 bench_command "parse" "" ./nitc --global --only-parse ../src/nitc.nit
136 bench_command "metamodel" "" ./nitc --global --only-metamodel ../src/nitc.nit
137 bench_command "generate c" "" ./nitc --global --no-cc ../src/nitc.nit
138 bench_command "full" "" ./nitc --global ../src/nitc.nit -o "nitc_nitc.bin"
139
140 prepare_res "$name-nitc-s.dat" "nitc-s" "Various steps of nitc --separate"
141 bench_command "parse" "" ./nitc --separate --only-parse ../src/nitc.nit
142 bench_command "metamodel" "" ./nitc --separate --only-metamodel ../src/nitc.nit
143 bench_command "generate c" "" ./nitc --separate --no-cc ../src/nitc.nit
144 bench_command "full" "" ./nitc --separate ../src/nitc.nit -o "nitc_nitc-e.bin"
145
146 prepare_res "$name-nitc-e.dat" "nitc-e" "Various steps of nitc --erasure"
147 bench_command "parse" "" ./nitc --erasure --only-parse ../src/nitc.nit
148 bench_command "metamodel" "" ./nitc --erasure --only-metamodel ../src/nitc.nit
149 bench_command "generate c" "" ./nitc --erasure --no-cc ../src/nitc.nit
150 bench_command "full" "" ./nitc --erasure ../src/nitc.nit -o "nitc_nitc-e.bin"
151
152 plot "$name.gnu"
153 }
154 bench_steps
155
156 # $#: options to compare
157 function bench_nitc-g_options()
158 {
159 tag=$1
160 shift
161 name="$FUNCNAME-$tag"
162 skip_test "$name" && return
163 prepare_res "$name.dat" "no options" "nitc-g without options"
164 run_compiler "nitc-g" ./nitc --global
165
166 if test "$1" = NOALL; then
167 shift
168 elif test -n "$2"; then
169 prepare_res "$name-all.dat" "all" "nitc-g with all options $@"
170 run_compiler "nitc-g-$tag" ./nitc --global $@
171 fi
172
173 for opt in "$@"; do
174 ot=${opt// /+}
175 prepare_res "$name$ot.dat" "$opt" "nitc-g with option $opt"
176 run_compiler "nitc-g$ot" ./nitc --global $opt
177 done
178
179 plot "$name.gnu"
180 }
181 bench_nitc-g_options "slower" --hardening --no-shortcut-range
182 bench_nitc-g_options "nocheck" --no-check-null --no-check-autocast --no-check-attr-isset --no-check-covariance --no-check-assert
183
184 function bench_nitc-s_options()
185 {
186 tag=$1
187 shift
188 name="$FUNCNAME-$tag"
189 skip_test "$name" && return
190 prepare_res "$name.dat" "no options" "nitc-s without options"
191 run_compiler "nitc-s" ./nitc --separate
192
193 if test "$1" = NOALL; then
194 shift
195 elif test -n "$2"; then
196 prepare_res "$name-all.dat" "all" "nitc-s with all options $@"
197 run_compiler "nitc-s-$tag" ./nitc --separate $@
198 fi
199
200 for opt in "$@"; do
201 ot=${opt// /+}
202 prepare_res "$name-$ot.dat" "$opt" "nitc-s with option $opt"
203 run_compiler "nitc-s$ot" ./nitc --separate $opt
204 done
205
206 plot "$name.gnu"
207 }
208 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"
209 bench_nitc-s_options "nocheck" --no-check-null --no-check-autocast --no-check-attr-isset --no-check-covariance --no-check-assert
210 bench_nitc-s_options "faster" --skip-dead-methods --inline-coloring-numbers --inline-some-methods --direct-call-monomorph "--inline-some-methods --direct-call-monomorph" ""
211
212 function bench_nitc-e_options()
213 {
214 tag=$1
215 shift
216 name="$FUNCNAME-$tag"
217 skip_test "$name" && return
218 prepare_res "$name.dat" "no options" "nitc-e without options"
219 run_compiler "nitc-e" ./nitc --erasure
220
221 if test "$1" = NOALL; then
222 shift
223 elif test -n "$2"; then
224 prepare_res "$name-all.dat" "all" "nitc-e with all options $@"
225 run_compiler "nitc-e-$tag" ./nitc --erasure $@
226 fi
227
228 for opt in "$@"; do
229 ot=${opt// /+}
230 prepare_res "$name$ot.dat" "$opt" "nitc-e with option $opt"
231 run_compiler "nitc-e$ot" ./nitc --erasure $opt
232 done
233
234 plot "$name.gnu"
235 }
236 bench_nitc-e_options "slower" --hardening --no-shortcut-equal --no-union-attribute --no-shortcut-range --no-inline-intern
237 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
238 bench_nitc-e_options "faster" --skip-dead-methods --inline-coloring-numbers --inline-some-methods --direct-call-monomorph --rta
239
240 function bench_engines()
241 {
242 name="$FUNCNAME"
243 skip_test "$name" && return
244 prepare_res "$name-nitc-s.dat" "nitc-s" "nitc with --separate"
245 run_compiler "nitc-s" ./nitc --separate
246 prepare_res "$name-nitc-e.dat" "nitc-e" "nitc with --erasure"
247 run_compiler "nitc-e" ./nitc --erasure
248 prepare_res "$name-nitc-sg.dat" "nitc-sg" "nitc with --separate --semi-global"
249 run_compiler "nitc-sg" ./nitc --separate --semi-global
250 prepare_res "$name-nitc-eg.dat" "nitc-eg" "nitc with --erasure --semi-global"
251 run_compiler "nitc-eg" ./nitc --erasure --semi-global
252 prepare_res "$name-nitc-egt.dat" "nitc-egt" "nitc with --erasure --semi-global --rta"
253 run_compiler "nitc-egt" ./nitc --erasure --semi-global --rta
254 prepare_res "$name-nitc-g.dat" "nitc-g" "nitc with --global"
255 run_compiler "nitc-g" ./nitc --global
256 plot "$name.gnu"
257 }
258 bench_engines
259
260 function bench_nitc-e_gc()
261 {
262 name="$FUNCNAME"
263 skip_test "$name" && return
264 prepare_res "$name-nitc-e.dat" "nitc-e" "nitc with --erasure"
265 run_compiler "nitc-e" ./nitc --erasure
266 prepare_res "$name-nitc-e-malloc.dat" "nitc-e-malloc" "nitc with --erasure and malloc"
267 NIT_GC_OPTION="malloc" run_compiler "nitc-e-malloc" ./nitc --erasure
268 prepare_res "$name-nitc-e-large.dat" "nitc-e-large" "nitc with --erasure and large"
269 NIT_GC_OPTION="large" run_compiler "nitc-e-large" ./nitc --erasure
270 plot "$name.gnu"
271 }
272 bench_nitc-e_gc
273
274 function bench_cc_nitc-e()
275 {
276 name="$FUNCNAME"
277 skip_test "$name" && return
278 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
279 f=`echo "$o" | cut -f1 -d:`
280 o=`echo "$o" | cut -f2 -d:`
281 prepare_res "$name-nitc-e-$f.dat" "nitc-e-$f" "nitc with --erasure --make-flags $o"
282 run_compiler "nitc-e-$f" ./nitc --erasure --make-flags "$o"
283 done
284 plot "$name.gnu"
285 }
286 bench_cc_nitc-e
287
288 function bench_policy()
289 {
290 name="$FUNCNAME"
291 skip_test "$name" && return
292 prepare_res "$name-nitc-s.dat" "nitc-s" "nitc with --separate"
293 run_compiler "nitc-s" ./nitc --separate
294 prepare_res "$name-nitc-e.dat" "nitc-e" "nitc with --erasure"
295 run_compiler "nitc-e" ./nitc --erasure
296 prepare_res "$name-nitc-su.dat" "nitc-su" "nitc with --separate --no-check-covariance"
297 run_compiler "nitc-su" ./nitc --separate --no-check-covariance
298 prepare_res "$name-nitc-eu.dat" "nitc-eu" "nitc with --erasure --no-check-covariance --no-check-erasure-cast"
299 run_compiler "nitc-eu" ./nitc --erasure --no-check-covariance --no-check-erasure-cast
300 plot "$name.gnu"
301 }
302 bench_policy
303
304 function bench_nullables()
305 {
306 name="$FUNCNAME"
307 skip_test "$name" && return
308 prepare_res "$name-nitc.dat" "nitc" "nitc no options"
309 run_compiler "nitc" ./nitc --separate
310 prepare_res "$name-nitc-ni.dat" "nitc-ni" "nitc --no-check-attr-isset"
311 run_compiler "nitc" ./nitc --separate --no-check-attr-isset
312 prepare_res "$name-nitc-nu.dat" "nitc-nu" "nitc --no-union-attribute"
313 run_compiler "nitc" ./nitc --separate --no-union-attribute
314 prepare_res "$name-nitc-nu-ni.dat" "nitc-nu-ni" "nitc --no-union-attribute --no-check-attr-isset"
315 run_compiler "nitc" ./nitc --separate --no-union-attribute --no-check-attr-isset
316 plot "$name.gnu"
317 }
318 bench_nullables
319
320 function bench_compilation_time
321 {
322 name="$FUNCNAME"
323 skip_test "$name" && return
324 prepare_res "$name-nitc-g.dat" "nitc-g" "nitc --global"
325 for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitc.nit; do
326 bench_command `basename "$i" .nit` "" ./nitc --global "$i" --no-cc
327 done
328 prepare_res "$name-nitc-s.dat" "nitc-s" "nitc --separate"
329 for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitc.nit; do
330 bench_command `basename "$i" .nit` "" ./nitc --separate "$i" --no-cc
331 done
332 prepare_res "$name-nitc-e.dat" "nitc-e" "nitc --erasure"
333 for i in ../examples/hello_world.nit ../src/test_parser.nit ../src/nitc.nit; do
334 bench_command `basename "$i" .nit` "" ./nitc --erasure "$i" --no-cc
335 done
336 plot "$name.gnu"
337 }
338 bench_compilation_time
339
340 function bench_linkboost()
341 {
342 name="$FUNCNAME"
343 skip_test "$name" && return
344 prepare_res "$name-nitc-st.dat" "nitc-st" "nitc with --separate --trampoline-call"
345 run_compiler "nitc-st" ./nitc --separate --trampoline-call
346 prepare_res "$name-nitc-s.dat" "nitc-s" "nitc with --separate"
347 run_compiler "nitc-s" ./nitc --separate
348 prepare_res "$name-nitc-sc.dat" "nitc-sc" "nitc with --separate --colors-are-symbols"
349 run_compiler "nitc-sc" ./nitc --separate --colors-are-symbols
350 prepare_res "$name-nitc-sct.dat" "nitc-sct" "nitc with --separate --colors-are-symbols --trampoline-call"
351 run_compiler "nitc-sct" ./nitc --separate --colors-are-symbols --trampoline-call
352 prepare_res "$name-nitc-sl.dat" "nitc-sl" "nitc with --separate --link-boost"
353 run_compiler "nitc-scts" ./nitc --separate --link-boost
354 prepare_res "$name-nitc-sg.dat" "nitc-sg" "nitc with --separate --semi-global"
355 run_compiler "nitc-sg" ./nitc --separate --semi-global
356 plot "$name.gnu"
357 }
358 bench_linkboost
359
360 if test -n "$html"; then
361 echo >>"$html" "</body></html>"
362 fi
363
364 echo >>"$xml" "</testsuite></testsuites>"
365
366 if test -n "$died"; then
367 echo "Some commands failed"
368 exit 1
369 fi
370 exit 0