bench/strings: Added bench for UTF-8 strings without index
[nit.git] / benchmarks / bench_strings.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 source ./bench_common.sh
17 source ./bench_plot.sh
18
19 # Default number of times a command must be run with bench_command
20 # Can be overrided with 'the option -n'
21 count=2
22
23 function usage()
24 {
25 echo "run_bench: [options]* bench_name args"
26 echo " -v: verbose mode"
27 echo " -n count: number of execution for each bar (default: $count)"
28 echo " -h: this help"
29 echo ""
30 echo "Benches : "
31 echo " all : all benches"
32 echo " - usage : * max_nb_cct loops strlen"
33 echo " iter: bench iterations"
34 echo " - usage : iter max_nb_cct loops strlen"
35 echo " cct: concatenation benching"
36 echo " - usage : cct max_nb_cct loops strlen"
37 echo " substr: substring benching"
38 echo " - usage : substr max_nb_cct loops strlen"
39 }
40
41 function benches()
42 {
43 bench_concat $@;
44 bench_iteration $@;
45 bench_substr $@;
46 }
47
48 function bench_concat()
49 {
50 if $verbose; then
51 echo "*** Benching concat performance ***"
52 fi
53
54 prepare_res concat_ropes.out concat_ropes ropes
55 if $verbose; then
56 echo "Ropes :"
57 fi
58 for i in `seq 1 "$1"`; do
59 if $verbose; then
60 echo "String length = $i, Concats/loop = $2, Loops = $3"
61 fi
62 bench_command $i ropes$i ./chain_concat -m rope --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
63 done
64
65 prepare_res concat_flat.out concat_flat flatstring
66 if $verbose; then
67 echo "FlatStrings :"
68 fi
69 for i in `seq 1 "$1"`; do
70 if $verbose; then
71 echo "String length = $i, Concats/loop = $2, Loops = $3"
72 fi
73 bench_command $i flatstring$i ./chain_concat -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
74 done
75
76 prepare_res concat_buf.out concat_buf flatbuffer
77 if $verbose; then
78 echo "FlatBuffers :"
79 fi
80 for i in `seq 1 "$1"`; do
81 if $verbose; then
82 echo "String length = $i, Concats/loop = $2, Loops = $3"
83 fi
84 bench_command $i flatbuffer$i ./chain_concat -m flatbuf --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
85 done
86
87 prepare_res concat_flatstr_utf8_noindex.out concat_flatstr_utf8_noindex flatstring_utf8_noindex
88 if $verbose; then
89 echo "FlatString UTF-8 (without index) :"
90 fi
91 for i in `seq 1 "$1"`; do
92 if $verbose; then
93 echo "String length = $i, Concats/loop = $2, Loops = $3"
94 fi
95 bench_command $i flatstr_utf8_noindex$i ./utf_chain_concat -m flatstr_utf8_noindex --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
96 done
97
98 plot concat.gnu
99 }
100
101 function bench_iteration()
102 {
103 if $verbose; then
104 echo "*** Benching iteration performance ***"
105 fi
106
107 prepare_res iter_ropes_iter.out iter_ropes_iter ropes_iter
108 if $verbose; then
109 echo "Ropes by iterator :"
110 fi
111 for i in `seq 1 "$1"`; do
112 if $verbose; then
113 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
114 fi
115 bench_command $i ropes_iter$i ./iteration_bench -m rope --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
116 done
117
118 prepare_res iter_ropes_index.out iter_ropes_index ropes_index
119 if $verbose; then
120 echo "Ropes by index :"
121 fi
122 for i in `seq 1 "$1"`; do
123 if $verbose; then
124 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
125 fi
126 bench_command $i ropes_index$i ./iteration_bench -m rope --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
127 done
128
129 prepare_res iter_flat_iter.out iter_flat_iter flatstring_iter
130 if $verbose; then
131 echo "FlatStrings by iterator :"
132 fi
133 for i in `seq 1 "$1"`; do
134 if $verbose; then
135 echo "String base length = $1, Concats = $i, Loops = $3"
136 fi
137 bench_command $i flatstr_iter$i ./iteration_bench -m flatstr --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
138 done
139
140 prepare_res iter_flat_index.out iter_flat_index flatstring_index
141 if $verbose; then
142 echo "FlatStrings by index :"
143 fi
144 for i in `seq 1 "$1"`; do
145 if $verbose; then
146 echo "String base length = $1, Concats = $i, Loops = $3"
147 fi
148 bench_command $i flatstr_index$i ./iteration_bench -m flatstr --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
149 done
150
151 prepare_res iter_buf_iter.out iter_buf_iter flatbuffer_iter
152 if $verbose; then
153 echo "FlatBuffers by iterator :"
154 fi
155 for i in `seq 1 "$1"`; do
156 if $verbose; then
157 echo "String base length = $1, Concats = $i, Loops = $3"
158 fi
159 bench_command $i flatbuf_iter$i ./iteration_bench -m flatbuf --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
160 done
161
162 prepare_res iter_buf_index.out iter_buf_index flatbuffer_index
163 if $verbose; then
164 echo "FlatBuffers by index:"
165 fi
166 for i in `seq 1 "$1"`; do
167 if $verbose; then
168 echo "String base length = $1, Concats = $i, Loops = $3"
169 fi
170 bench_command $i flatbuf_index$i ./iteration_bench -m flatbuf --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
171 done
172
173 prepare_res iter_flat_utf8_noindex_iter.out iter_flat_iter_utf8_noindex flatstring_utf8_noindex_iter
174 if $verbose; then
175 echo "FlatStrings by iterator :"
176 fi
177 for i in `seq 1 "$1"`; do
178 if $verbose; then
179 echo "String base length = $1, Concats = $i, Loops = $3"
180 fi
181 bench_command $i flatstr_iter_utf8_noindex$i ./utf_iteration_bench -m flatstr_utf8_noindex --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
182 done
183
184 prepare_res iter_flat_utf8_noindex_index.out iter_flat_index_utf8_noindex flatstring_utf8_noindex_index
185 if $verbose; then
186 echo "FlatStrings by index :"
187 fi
188 for i in `seq 1 "$1"`; do
189 if $verbose; then
190 echo "String base length = $1, Concats = $i, Loops = $3"
191 fi
192 bench_command $i flatstr_index_utf8_noindex$i ./utf_iteration_bench -m flatstr_utf8_noindex --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
193 done
194
195 plot iter.gnu
196 }
197
198 function bench_substr()
199 {
200 if $verbose; then
201 echo "*** Benching substring performance ***"
202 fi
203
204 prepare_res substr_ropes.out substr_ropes ropes
205 if $verbose; then
206 echo "Ropes :"
207 fi
208 for i in `seq 1 "$1"`; do
209 if $verbose; then
210 echo "String length = $i, loops = $2, Loops = $3"
211 fi
212 bench_command $i ropes$i ./substr_bench -m rope --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
213 done
214
215 prepare_res substr_flat.out substr_flat flatstring
216 if $verbose; then
217 echo "FlatStrings :"
218 fi
219 for i in `seq 1 "$1"`; do
220 if $verbose; then
221 echo "String length = $i, loops = $2, Loops = $3"
222 fi
223 bench_command $i flatstring$i ./substr_bench -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
224 done
225
226 prepare_res substr_buf.out substr_buf flatbuffer
227 if $verbose; then
228 echo "FlatBuffers :"
229 fi
230 for i in `seq 1 "$1"`; do
231 if $verbose; then
232 echo "String length = $i, loops = $2, Loops = $3"
233 fi
234 bench_command $i flatbuffer$i ./substr_bench -m flatbuf --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
235 done
236
237 prepare_res substr_flat_utf8_noindex.out substr_flat_utf8_noindex flatstring_utf8_noindex
238 if $verbose; then
239 echo "FlatStrings UTF-8 (without index) :"
240 fi
241 for i in `seq 1 "$1"`; do
242 if $verbose; then
243 echo "String length = $i, loops = $2, Loops = $3"
244 fi
245 bench_command $i flatstring_utf8_noindex$i ./utf_substr_bench -m flatstr_utf8_noindex --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
246 done
247
248 plot substr.gnu
249 }
250
251 stop=false
252 while [ "$stop" = false ]; do
253 case "$1" in
254 -v) verbose=true; shift;;
255 -h) usage; exit;;
256 -n) count="$2"; shift; shift;;
257 *) stop=true
258 esac
259 done
260
261 if test $# -ne 4; then
262 usage
263 exit
264 fi
265
266 if $verbose; then
267 echo "Compiling"
268 fi
269
270 ../bin/nitg --global ./strings/chain_concat.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
271 ../bin/nitg --global ./strings/utf_chain_concat.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
272 ../bin/nitg --global ./strings/iteration_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
273 ../bin/nitg --global ./strings/utf_iteration_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
274 ../bin/nitg --global ./strings/substr_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
275 ../bin/nitg --global ./strings/utf_substr_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
276
277 case "$1" in
278 iter) shift; bench_iteration $@ ;;
279 cct) shift; bench_concat $@ ;;
280 substr) shift; bench_substr $@ ;;
281 all) shift; benches $@ ;;
282 *) usage; exit;;
283 esac