README: document nit_env.sh
[nit.git] / benchmarks / bench_languages.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 ## HANDLE OPTIONS ##
30
31 function usage()
32 {
33 echo "run_bench: [options]* benchname"
34 echo " -v: verbose mode"
35 echo " -n count: number of execution for each bar (default: $count)"
36 echo " --dry: Do not run the commands, just reuse the data and generate the graph"
37 echo " --fast: Run less and faster tests"
38 echo " -h: this help"
39 }
40
41 stop=false
42 while [ "$stop" = false ]; do
43 case "$1" in
44 -v) verbose=true; shift;;
45 -h) usage; exit;;
46 -n) count="$2"; shift; shift;;
47 --dry) dry_run=true; shift;;
48 --fast) fast=true; shift;;
49 *) stop=true
50 esac
51 done
52
53 NOTSKIPED="$*"
54
55 if test -z "$NOTSKIPED"; then
56 usage
57 echo "List of available benches:"
58 echo "* all: run all the benches"
59 fi
60
61 ## COMPILE ENGINES
62 cd ../src
63 test -f ./nitc_3 || ./ncall.sh -O
64 cd ../benchmarks
65 test -f ./nitc || ../src/nitc_3 ../src/nitc.nit -O -v
66
67 ## EFFECTIVE BENCHS ##
68
69 function bench_language()
70 {
71 name="$1"
72 skip_test "$name" && return
73 rootdir=`pwd`
74 basedir="./${name}.out"
75
76 mkdir $basedir
77
78 t=t
79 s=20
80 seq="2 4 8"
81 for b in $seq; do
82 run_command ./nitc languages/$name.nit -o $basedir/$name.bin
83 run_command $basedir/$name.bin $basedir "${t}_$b" "$b"
84 done
85
86 prepare_res $basedir/$name-g++.dat "g++" "g++"
87 cppdir="${basedir}/cpp"
88 for b in $seq; do
89 run_command g++ "${cppdir}/${t}_$b.cpp" -O2 -o "${cppdir}/${t}_$b.g++.bin"
90 bench_command "$b" "" "${cppdir}/${t}_$b.g++.bin" $s
91 done
92
93 prepare_res $basedir/$name-clang++.dat "clang++" "clang++"
94 for b in $seq; do
95 run_command clang++ "${cppdir}/${t}_$b.cpp" -O2 -o "${cppdir}/${t}_$b.clang++.bin"
96 bench_command "$b" "" "${cppdir}/${t}_$b.clang++.bin" $s
97 done
98
99 prepare_res $basedir/$name-java.dat "java" "java"
100 javadir="${basedir}/java"
101 for b in $seq; do
102 run_command javac "${javadir}/${t}_$b.java"
103 bench_command "$b" "" java -cp "${javadir}/" "${t}_$b" $s
104 done
105
106 prepare_res $basedir/$name-gcj.dat "gcj" "gcj"
107 for b in $seq; do
108 run_command gcj --main=${t}_$b -O2 "${javadir}/${t}_$b.java" -o "${javadir}/${t}_$b.gcj.bin"
109 bench_command "$b" "" "${javadir}/${t}_$b.gcj.bin" $s
110 done
111
112 prepare_res $basedir/$name-scala.dat "scala" "scala"
113 scaladir="${basedir}/scala"
114 for b in $seq; do
115 run_command scalac "${scaladir}/${t}_$b.scala" -d "${scaladir}"
116 bench_command "$b" "" scala -cp "${scaladir}/" "${t}_$b" $s
117 done
118
119 prepare_res $basedir/$name-cs.dat "c#" "c#"
120 csdir="${basedir}/cs"
121 for b in $seq; do
122 run_command gmcs "$csdir/${t}_$b.cs"
123 bench_command "$b" "" mono "$csdir/${t}_$b.exe" $s
124 done
125
126 prepare_res $basedir/$name-es.dat "es" "es"
127 esdir="${basedir}/es"
128 for b in $seq; do
129 cd $esdir
130 run_command ec -clean -finalize ${t}_$b/app${t}_$b.e
131 chmod +x app${t}_$b
132 mv app${t}_$b ${t}_$b.es.bin
133 cd $rootdir
134 bench_command "$b" "" "$esdir/${t}_$b.es.bin" $s
135 done
136
137 prepare_res $basedir/$name-se.dat "se" "se"
138 sedir="${basedir}/se"
139 for b in $seq; do
140 cd $sedir
141 run_command se compile -no_check app${t}_${b}_se.e -loadpath ${t}_${b}_se -o ${t}_$b.se.bin
142 cd $rootdir
143 bench_command "$b" "" "$sedir/${t}_$b.se.bin" $s
144 done
145
146 nitdir="${basedir}/nit"
147 prepare_res $nitdir/$name-nitc.dat "nitc" "nitc"
148 for b in $seq; do
149 run_command ./nitc $nitdir/${t}_$b.nit --global -o "$nitdir/${t}_$b.nitc.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
150 bench_command "$b" "" "$nitdir/${t}_$b.nitc.bin" $s
151 done
152
153 prepare_res $nitdir/$name-nitc-s.dat "nitc-s" "nitc-s"
154 for b in $seq; do
155 run_command ./nitc $nitdir/${t}_$b.nit --separate -o "$nitdir/${t}_$b.nitc-s.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
156 bench_command "$b" "" "$nitdir/${t}_$b.nitc-s.bin" $s
157 done
158
159 <<XXX
160 prepare_res $nitdir/$name-nitc-su.dat "nitc-su" "nitc-su"
161 for b in $seq; do
162 run_command ./nitc $nitdir/${t}_$b.nit --separate --no-check-covariance -o "$nitdir/${t}_$b.nitc-su.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
163 bench_command "$b" "" "$nitdir/${t}_$b.nitc-su.bin" $s
164 done
165
166 prepare_res $nitdir/$name-nitc-e.dat "nitc-e" "nitc-e"
167 for b in $seq; do
168 run_command ./nitc $nitdir/${t}_$b.nit --erasure -o "$nitdir/${t}_$b.nitc-e.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
169 bench_command "$b" "" "$nitdir/${t}_$b.nitc-e.bin" $s
170 done
171
172 prepare_res $nitdir/$name-nitc-eu.dat "nitc-eu" "nitc-eu"
173 for b in $seq; do
174 run_command ./nitc $nitdir/${t}_$b.nit --erasure --no-check-covariance --no-check-erasure-cast -o "$nitdir/${t}_$b.nitc-eu.bin" --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
175 bench_command "$b" "" "$nitdir/${t}_$b.nitc-eu.bin" $s
176 done
177 XXX
178
179 plot $basedir/$name.gnu
180 }
181
182 for name in languages/*.nit; do
183 n=`basename $name .nit`
184 bench_language $n
185 done
186
187 if test -n "$died"; then
188 echo "Some commands failed"
189 exit 1
190 fi
191 exit 0