53eb38c63e1ba9e4e074e464a18c4c84430eab77
[nit.git] / benchmarks / bench_nitunit.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 # Bench nitdoc perfs.
17
18 source ./bench_common.sh
19 source ./bench_plot.sh
20
21 ## CONFIGURATION OPTIONS ##
22
23 # Default number of times a command must be run with bench_command
24 # Can be overrided with 'the option -n'
25 count=3
26
27 ### HELPER FUNCTIONS ##
28
29 function die()
30 {
31 echo >&2 "error: $*"
32 died=1
33 }
34
35 ## HANDLE OPTIONS ##
36
37 function usage()
38 {
39 echo "bench_nitunit [options]*"
40 echo " -v: verbose mode"
41 echo " -n count: number of execution for each bar (default: $count)"
42 echo " --dry: Do not run the commands, just reuse the data and generate the graph"
43 echo " -h: this help"
44 }
45
46 stop=false
47 while [ "$stop" = false ]; do
48 case "$1" in
49 -v) verbose=true; shift;;
50 -h) usage; exit;;
51 -n) count="$2"; shift; shift;;
52 --dry) dry_run=true; shift;;
53 *) stop=true
54 esac
55 done
56
57 NOTSKIPED="$*"
58
59 if test -z "$NOTSKIPED"; then
60 usage
61 fi
62
63 ## COMPILE ENGINES
64 current_branch=`git rev-parse --abbrev-ref HEAD`
65 git checkout origin/master && ../bin/nitc ../src/nitunit.nit -o ./nitunit.orig
66 git checkout $current_branch && ../bin/nitc ../src/nitunit.nit -o ./nitunit.new
67
68 ## EFFECTIVE BENCHS ##
69
70 function bench_nitunit()
71 {
72 basedir="./bench_nitunit.out/${name}.out"
73 tests=(../lib/standard/kernel.nit ../lib/standard/string.nit ../lib/standard/collection)
74 mkdir -p $basedir
75
76 prepare_res $basedir/orig.dat "origin/master" "nitunit.orig"
77 for path in ${tests[@]}; do
78 run_gen ./nitunit.orig $path
79 done
80
81 prepare_res $basedir/new.dat "HEAD" "nitunit.new"
82 for path in ${tests[@]}; do
83 run_gen ./nitunit.new $path
84 done
85
86 plot $basedir/bench_nitunit.gnu
87 }
88
89 function run_gen()
90 {
91 bin="$1"
92 path="$2"
93 name=`basename $path .nit`
94 bench_command $name $path $bin $path
95 }
96
97 bench_nitunit
98
99 if test -n "$died"; then
100 echo "Some commands failed"
101 exit 1
102 fi
103 exit 0