benchmarks/markdown: make `$s` configurable
[nit.git] / benchmarks / markdown / bench_markdown.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 # Shell script to bench nitmd over different kind of document.
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=2
26
27 # Default number of times the input file is transformed during a single run
28 s=200
29
30 ### HELPER FUNCTIONS ##
31
32 function die()
33 {
34 echo >&2 "error: $*"
35 died=1
36 }
37
38 ## HANDLE OPTIONS ##
39
40 function usage()
41 {
42 echo "run_bench: [options]* benchname"
43 echo " -v: verbose mode"
44 echo " -n count: number of execution for each bar (default: $count)"
45 echo " -s size: number of transformations for each run (default: $s)"
46 echo " --dry: Do not run the commands, just reuse the data and generate the graph"
47 echo " -h: this help"
48 }
49
50 stop=false
51 while [ "$stop" = false ]; do
52 case "$1" in
53 -v) verbose=true; shift;;
54 -h) usage; exit;;
55 -n) count="$2"; shift; shift;;
56 -s) s="$2"; shift; shift;;
57 --dry) dry_run=true; shift;;
58 *) stop=true
59 esac
60 done
61
62 ## GEN BENCHES
63 cd benches; make; cd ..
64
65 ## COMPILE ENGINES
66 cd engines; make; cd ..
67
68 NOTSKIPED="$*"
69
70 if test -z "$NOTSKIPED"; then
71 usage
72 echo "List of available benches:"
73 echo "* all: run all the benches"
74 fi
75
76 ## EFFECTIVE BENCHS ##
77 outdir="./out"
78 engdir="./engines"
79 bncdir="./benches/out"
80 mkdir -p $outdir
81
82 function bench_nitmd()
83 {
84 name="$FUNCNAME"
85 skip_test "$name" && return
86 prepare_res $outdir/nitmd.dat "nitmd" "nitmd"
87 for file in $bncdir/*.md; do
88 bench=`basename $file .md`
89 bench_command "$bench" "" "$engdir/nitmd/nitmd" "$file" "$s"
90 done
91 }
92 bench_nitmd
93
94 function bench_nitmd-o()
95 {
96 name="$FUNCNAME"
97 skip_test "$name" && return
98 prepare_res $outdir/nitmd-o.dat "nitmd-o" "nitmd-o"
99 for file in $bncdir/*.md; do
100 bench=`basename $file .md`
101 bench_command "$bench" "" "$engdir/nitmd/nitmd-o" "$file" "$s"
102 done
103 }
104 bench_nitmd-o
105
106 function bench_txtmark()
107 {
108 name="$FUNCNAME"
109 skip_test "$name" && return
110 prepare_res $outdir/txtmark.dat "txtmark" "txtmark"
111 for file in $bncdir/*.md; do
112 bench=`basename $file .md`
113 bench_command "$bench" "" "java" "-cp" "$engdir/txtmark/.:$engdir/txtmark/txtmark-0.11.jar" "Txtmark" "$file" "$s"
114 done
115 }
116 bench_txtmark
117
118 function bench_markdown4j()
119 {
120 name="$FUNCNAME"
121 skip_test "$name" && return
122 prepare_res $outdir/markdown4j.dat "markdown4j" "markdown4j"
123 for file in $bncdir/*.md; do
124 name=`basename $file .md`
125 bench_command "$bench" "" "java" "-cp" "$engdir/markdown4j/.:$engdir/markdown4j/markdown4j-2.2.jar" "Markdown4j" "$file" "$s"
126 done
127 }
128 bench_markdown4j
129
130 function bench_pandoc()
131 {
132 name="$FUNCNAME"
133 skip_test "$name" && return
134 prepare_res $outdir/pandoc.dat "pandoc" "pandoc"
135 for file in $bncdir/*.md; do
136 name=`basename $file .md`
137 bench_command "$bench" "" "$engdir/pandoc/pandoc" "$file" "$s"
138 done
139 }
140 bench_pandoc
141
142 if test "$#" -gt 0; then
143 plot $outdir/bench_markdown.gnu
144 fi
145
146 if test -n "$died"; then
147 echo "Some commands failed"
148 exit 1
149 fi
150 exit 0