Merge: benches/markdown: add `pandoc` engine.
[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 ### 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 "run_bench: [options]* benchname"
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 ## GEN BENCHES
58 cd benches; make; cd ..
59
60 ## COMPILE ENGINES
61 cd engines; make; cd ..
62
63 NOTSKIPED="$*"
64
65 if test -z "$NOTSKIPED"; then
66 usage
67 echo "List of available benches:"
68 echo "* all: run all the benches"
69 fi
70
71 ## EFFECTIVE BENCHS ##
72 outdir="./out"
73 engdir="./engines"
74 bncdir="./benches/out"
75 mkdir -p $outdir
76
77 s=200
78
79 function bench_nitmd()
80 {
81 name="$FUNCNAME"
82 skip_test "$name" && return
83 prepare_res $outdir/nitmd.dat "nitmd" "nitmd"
84 for file in $bncdir/*.md; do
85 bench=`basename $file .md`
86 bench_command "$bench" "" "$engdir/nitmd/nitmd" "$file" "$s"
87 done
88 }
89 bench_nitmd
90
91 function bench_nitmd-o()
92 {
93 name="$FUNCNAME"
94 skip_test "$name" && return
95 prepare_res $outdir/nitmd-o.dat "nitmd-o" "nitmd-o"
96 for file in $bncdir/*.md; do
97 bench=`basename $file .md`
98 bench_command "$bench" "" "$engdir/nitmd/nitmd-o" "$file" "$s"
99 done
100 }
101 bench_nitmd-o
102
103 function bench_txtmark()
104 {
105 name="$FUNCNAME"
106 skip_test "$name" && return
107 prepare_res $outdir/txtmark.dat "txtmark" "txtmark"
108 for file in $bncdir/*.md; do
109 bench=`basename $file .md`
110 bench_command "$bench" "" "java" "-cp" "$engdir/txtmark/.:$engdir/txtmark/txtmark-0.11.jar" "Txtmark" "$file" "$s"
111 done
112 }
113 bench_txtmark
114
115 function bench_markdown4j()
116 {
117 name="$FUNCNAME"
118 skip_test "$name" && return
119 prepare_res $outdir/markdown4j.dat "markdown4j" "markdown4j"
120 for file in $bncdir/*.md; do
121 name=`basename $file .md`
122 bench_command "$bench" "" "java" "-cp" "$engdir/markdown4j/.:$engdir/markdown4j/markdown4j-2.2.jar" "Markdown4j" "$file" "$s"
123 done
124 }
125 bench_markdown4j
126
127 function bench_pandoc()
128 {
129 name="$FUNCNAME"
130 skip_test "$name" && return
131 prepare_res $outdir/pandoc.dat "pandoc" "pandoc"
132 for file in $bncdir/*.md; do
133 name=`basename $file .md`
134 bench_command "$bench" "" "$engdir/pandoc/pandoc" "$file" "$s"
135 done
136 }
137 bench_pandoc
138
139 if test "$#" -gt 0; then
140 plot $outdir/bench_markdown.gnu
141 fi
142
143 if test -n "$died"; then
144 echo "Some commands failed"
145 exit 1
146 fi
147 exit 0