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 # This shell script helps running benchmarks
18 # TODO: cleanup and libify the helper-parts
20 ## CONFIGURATION OPTIONS ##
22 # Number of times a command must be run with bench_command
26 #outputopts=">/dev/null 2>&1"
32 ### HELPER FUNCTIONS ##
40 # Run a single command multiple time and store the execution times
41 # in the current $res file.
43 # $1: title of the command
44 # $2: long desription of the command
45 # rest: the command to execute
46 function bench_command
()
48 if [ "$dry_run" = "true" ]; then return; fi
54 echo "$title" > "$timeout"
55 echo "# $desc" >> "$timeout"
56 echo "\$ $@" >> "$timeout"
58 echo "** [$title] $desc **"
61 # Execute the commands $count times
62 for i
in `seq 1 "$count"`; do
63 /usr
/bin
/time -f
"%U" -o
"$timeout" -a
"$@" $outputopts # || die "$1: failed"
68 line
=`compute_stats "$timeout"`
73 # Run a simble command witout storing the execution time
74 # Used to display command on verbose and skip long executions when dry_run is given
75 # $@ command to execute
76 function run_command
()
78 if [ "$dry_run" = "true" ]; then return; fi
83 # perl function to compute min/max/avg.
84 # used by bench_command
87 # return: first min max avg label
88 function compute_stats
()
92 perl
- "$file" <<'END'
106 $len = scalar @lines
;
108 @lines
= sort {$a <=> $b} @lines
;
110 $max = $lines[$#lines];
112 for $i (@lines
) { $avg += $i; }
114 print
"${first} ${min} ${max} ${avg} \"${label}\"\n";
116 print
"${first} ${first} ${first} ${first} \"${label}\"\n";
121 # Create a new $res to be used in the next plot
126 function prepare_res
()
131 if [ "$plots" = "" ]; then
132 plots
="plot '$1' using 4:xticlabels(5) ti '$2';"
134 plots
="$plots replot '$1' using 4 ti '$2';"
136 if [ "$dry_run" = "true" ]; then return; fi
137 echo "# [$2] $3" > "$res"
138 echo "# first min max avg title" >> "$res"
141 # Plot the last $res as an histogram
142 # $1: plot file (eg toto.gnu)
148 set style data histogram
;
149 set style histogram cluster gap
2;
150 set style fill solid border
-1;
152 set xtic nomirror rotate by
-45 scale
0 font
',8';
154 set ylabel
"time (s)"
157 echo "# gnuplot -p $1"
162 ## GLOBAL VARIABLES ##
164 # The current $res (set by prepare_res, used by bench_command)
167 # The current stuff to plot (set by prepare_res, used by plot)
172 # Run standards benchs on a compiler command
174 # rest: command to run (executable + options)
175 function run_compiler
()
179 run_command
"$@" nitg.nit
-o
"nitg.$title.bin"
180 bench_command
"nitg" "nitg test_parser.nit" "./nitg.$title.bin" test_parser.nit
181 run_command
"$@" nit.nit
-o
"nit.$title.bin"
182 bench_command
"nit" "nit test_parser.nit test_parser.nit" "./nit.$title.bin" test_parser.nit
-- -n rapid_type_analysis.nit
185 ## EFFECTIVE BENCHS ##
187 function bench_nitg_bootstrap
()
190 prepare_res
"$name.dat" "" "Steps of the bootstrap of nitg by nitc"
192 cp .
/nitc_3 .
/nitc_nitc
193 bench_command
"c/c c" "nitc_nitc nitc.nit -> nitc_nitc (stability)" .
/nitc_nitc
-O nitc.nit
-o nitc_nitc
194 bench_command
"c/c g" "nitc_nitc nitg.nit -> nitg_nitc" .
/nitc_nitc
-O nitg.nit
-o nitg_nitc
195 bench_command
"g/c g" "nitg_nitc nitg.nit -> nitg_nitg" .
/nitg_nitc nitg.nit
-o nitg_nitg
196 bench_command
"g/g g" "nitg_nitg nitg.nit -> nitg_nitg (stability)" .
/nitg_nitg nitg.nit
-o nitg_nitg
202 function bench_steps
()
205 prepare_res
"$name-nitc.dat" "nitc" "Various steps of nitc"
206 bench_command
"parse" "" .
/nitc_3
--only
-parse nitg.nit
207 bench_command
"metamodel" "" .
/nitc_3
--only
-metamodel nitg.nit
208 bench_command
"generate c" "" .
/nitc_3
--no
-cc nitg.nit
209 bench_command
"full" "" .
/nitc_nitc
-O nitg.nit
211 prepare_res
"$name-nitg.dat" "nitg" "Various steps of nitg"
212 bench_command
"parse" "" .
/nitg
--only
-parse nitg.nit
213 bench_command
"metamodel" "" .
/nitg
--only
-metamodel nitg.nit
214 bench_command
"generate c" "" .
/nitg
--no
-cc nitg.nit
215 bench_command
"full" "" .
/nitg nitg.nit
221 # $#: options to compare
222 function bench_nitg_options
()
225 prepare_res
"$name.dat" "no options" "nitg without options"
226 run_compiler
"nitg" .
/nitg
229 prepare_res
"$name$opt.dat" "$opt" "nitg with option $opt"
230 run_compiler
"nitg$opt" .
/nitg
$opt
235 bench_nitg_options
--hardening
237 function bench_nitc_gc
()
240 for gc
in nitgc boehm malloc large
; do
241 prepare_res
"$name-$gc".dat
"$gc" "nitc with gc=$gc"
242 export NIT_GC_OPTION
="$gc"
243 run_compiler
"nitc" .
/nitc_3
-O
250 function bench_nitc_boost
()
253 prepare_res
"$name-slow.dat" "no -O" "nitc without -O"
254 run_compiler
"nitc_slow" .
/nitc_3
255 prepare_res
"$name-fast.dat" "-O" "nitc with -O"
256 run_compiler
"nitc" .
/nitc_3
-O
262 function bench_engines
()
265 prepare_res
"$name-nitc.dat" "nitc" "nitc"
266 run_compiler
"nitc" .
/nitc_3
-O
267 prepare_res
"$name-nitc-g.dat" "nitc-g" "nitc with --global"
268 run_compiler
"nitc-g" .
/nitc_3
-O
--global
269 prepare_res
"$name-nitg.dat" "nitg" "nitg"
270 run_compiler
"nitg" .
/nitg
275 function bench_compilation_time
278 prepare_res
"$name-nitc.dat" "nitc" "nitc"
279 for i
in ..
/examples
/hello_world.nit test_parser.nit nitg.nit
; do
280 bench_command
`basename "$i" .nit` "" .
/nitc_3
-O
"$i" --no
-cc
282 prepare_res
"$name-nitg.dat" "nitg" "nitg"
283 for i
in ..
/examples
/hello_world.nit test_parser.nit nitg.nit
; do
284 bench_command
`basename "$i" .nit` "" .
/nitg
"$i" --no
-cc
286 prepare_res
"$name-nitg_g.dat" "nitg/g" "nitg/g"
287 for i
in ..
/examples
/hello_world.nit test_parser.nit nitg.nit
; do
288 bench_command
`basename "$i" .nit` "" .
/nitg.bin
"$i" --no
-cc
292 bench_compilation_time