benchmarks/string: Updated bench scripts for strings
[nit.git] / benchmarks / strings / 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=5
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 " iter: bench iterations"
32 echo " - usage : iter max_nb_cct loops strlen"
33 echo " cct: concatenation benching"
34 echo " - usage : cct max_nb_cct loops strlen"
35 echo " substr: substring benching"
36 echo " - usage : substr max_nb_cct loops strlen"
37 echo " array: Benchmark for the to_s in array"
38 echo " - usage : array nb_cct loops max_arrlen"
39 }
40
41 function bench_array()
42 {
43 if [ -d arraytos ]; then
44 rm arraytos/*
45 else
46 mkdir arraytos
47 fi
48 cd arraytos
49
50 if $verbose; then
51 echo "*** Benching Array.to_s performance ***"
52 fi
53
54 ../../../bin/nitc --global ../array_tos.nit -m ../array_to_s_vars/array_to_s_rope.nit
55
56 prepare_res arr_tos_ropes.out arr_tos_ropes ropes
57 if $verbose; then
58 echo "Ropes :"
59 fi
60 for i in `seq 1 "$3"`; do
61 if $verbose; then
62 echo "String length = $i, Concats/loop = $1, Loops = $2"
63 fi
64 bench_command $i ropes$i ./array_tos --loops $2 --strlen $i --ccts $1
65 done
66
67 ../../../bin/nitc --global ../array_tos.nit -m ../array_to_s_vars/array_to_s_flatstr.nit
68
69 prepare_res arr_tos_flat.out arr_tos_flat flatstring
70 if $verbose; then
71 echo "FlatStrings :"
72 fi
73 for i in `seq 1 "$3"`; do
74 if $verbose; then
75 echo "String length = $i, Concats/loop = $1, Loops = $2"
76 fi
77 bench_command $i flatstring$i ./array_tos --loops $2 --strlen $i --ccts $1
78 done
79
80 ../../../bin/nitc --global ../array_tos.nit -m ../array_to_s_vars/array_to_s_buffer.nit
81
82 prepare_res arr_tos_buf.out arr_tos_buf flatbuffer
83 if $verbose; then
84 echo "FlatBuffers :"
85 fi
86 for i in `seq 1 "$3"`; do
87 if $verbose; then
88 echo "String length = $i, Concats/loop = $1, Loops = $2"
89 fi
90 bench_command $i flatbuffer$i ./array_tos --loops $2 --strlen $i --ccts $1
91 done
92
93 ../../../bin/nitc --global ../array_tos.nit -m ../array_to_s_vars/array_to_s_manual.nit
94
95 prepare_res arr_tos_man.out arr_tos_man memmove
96 if $verbose; then
97 echo "Memmove :"
98 fi
99 for i in `seq 1 "$3"`; do
100 if $verbose; then
101 echo "String length = $i, Concats/loop = $1, Loops = $2"
102 fi
103 bench_command $i memmove$i ./array_tos --loops $2 --strlen $i --ccts $1
104 done
105
106 ../../../bin/nitc --global ../array_tos.nit -m ../array_to_s_vars/array_to_s_man_buf.nit
107
108 prepare_res arr_tos_man_buf.out arr_tos_man_buf flatbuf_with_capacity
109 if $verbose; then
110 echo "FlatBuffer.with_capacity :"
111 fi
112 for i in `seq 1 "$3"`; do
113 if $verbose; then
114 echo "String length = $i, Concats/loop = $1, Loops = $2"
115 fi
116 bench_command $i flatbuf_with_capacity$i ./array_tos --loops $2 --strlen $i --ccts $1
117 done
118
119 ../../../bin/nitc --global ../array_tos.nit -m ../array_to_s_vars/array_to_s_rope_buf.nit
120
121 prepare_res arr_tos_rope_buf.out arr_tos_rope_buf ropebuf
122 if $verbose; then
123 echo "RopeBuffer :"
124 fi
125 for i in `seq 1 "$3"`; do
126 if $verbose; then
127 echo "String length = $i, Concats/loop = $1, Loops = $2"
128 fi
129 bench_command $i ropebuf$i ./array_tos --loops $2 --strlen $i --ccts $1
130 done
131
132 plot array_tos.gnu
133
134 cd ..
135 }
136
137 function bench_concat()
138 {
139 if [ -d string_concat ]; then
140 rm string_concat/*
141 else
142 mkdir string_concat
143 fi
144 cd string_concat
145
146 ../../../bin/nitc --global ../chain_concat.nit
147
148 if $verbose; then
149 echo "*** Benching concat performance ***"
150 fi
151
152 prepare_res concat_flat.out concat_flat flatstring
153 if $verbose; then
154 echo "FlatStrings :"
155 fi
156 for i in `seq 1 "$1"`; do
157 if $verbose; then
158 echo "String length = $i, Concats/loop = $2, Loops = $3"
159 fi
160 bench_command $i flatstring$i ./chain_concat -m flatstr --loops $2 --strlen $3 --ccts $i
161 done
162
163 prepare_res concat_buf.out concat_buf flatbuffer
164 if $verbose; then
165 echo "FlatBuffers :"
166 fi
167 for i in `seq 1 "$1"`; do
168 if $verbose; then
169 echo "String length = $i, Concats/loop = $2, Loops = $3"
170 fi
171 bench_command $i flatbuffer$i ./chain_concat -m flatbuf --loops $2 --strlen $3 --ccts $i
172 done
173
174 prepare_res concat_ropes.out concat_ropes ropes
175 if $verbose; then
176 echo "Ropes :"
177 fi
178 for i in `seq 1 "$1"`; do
179 if $verbose; then
180 echo "String length = $i, Concats/loop = $2, Loops = $3"
181 fi
182 bench_command $i ropes$i ./chain_concat -m ropestr --loops $2 --strlen $3 --ccts $i
183 done
184
185 prepare_res concat_buf_ropes.out concat_buf_ropes buffered_ropes
186 if $verbose; then
187 echo "Rope Buffer:"
188 fi
189 for i in `seq 1 "$1"`; do
190 if $verbose; then
191 echo "string length = $i, concats/loop = $2, loops = $3"
192 fi
193 bench_command $i buf_ropes$i ./chain_concat -m ropebuf --loops $2 --strlen $3 --ccts $i
194 done
195
196 plot concat.gnu
197
198 cd ..
199 }
200
201 function bench_iteration()
202 {
203 if [ -d string_iter ]; then
204 rm string_iter/*
205 else
206 mkdir string_iter
207 fi
208 cd string_iter
209
210 if $verbose; then
211 echo "*** Benching iteration performance ***"
212 fi
213
214 ../../../bin/nitc --global ../iteration_bench.nit
215
216 prepare_res iter_flat_iter.out iter_flat_iter flatstring_iter
217 if $verbose; then
218 echo "FlatStrings by iterator :"
219 fi
220 for i in `seq 1 "$1"`; do
221 if $verbose; then
222 echo "String base length = $1, Concats = $i, Loops = $3"
223 fi
224 bench_command $i flatstr_iter$i ./iteration_bench -m flatstr --iter-mode iterator --loops $2 --strlen $3 --ccts $i
225 done
226
227 prepare_res iter_flat_index.out iter_flat_index flatstring_index
228 if $verbose; then
229 echo "FlatStrings by index :"
230 fi
231 for i in `seq 1 "$1"`; do
232 if $verbose; then
233 echo "String base length = $1, Concats = $i, Loops = $3"
234 fi
235 bench_command $i flatstr_index$i ./iteration_bench -m flatstr --iter-mode index --loops $2 --strlen $3 --ccts $i
236 done
237
238 prepare_res iter_buf_iter.out iter_buf_iter flatbuffer_iter
239 if $verbose; then
240 echo "FlatBuffers by iterator :"
241 fi
242 for i in `seq 1 "$1"`; do
243 if $verbose; then
244 echo "String base length = $1, Concats = $i, Loops = $3"
245 fi
246 bench_command $i flatbuf_iter$i ./iteration_bench -m flatbuf --iter-mode iterator --loops $2 --strlen $3 --ccts $i
247 done
248
249 prepare_res iter_buf_index.out iter_buf_index flatbuffer_index
250 if $verbose; then
251 echo "FlatBuffers by index:"
252 fi
253 for i in `seq 1 "$1"`; do
254 if $verbose; then
255 echo "String base length = $1, Concats = $i, Loops = $3"
256 fi
257 bench_command $i flatbuf_index$i ./iteration_bench -m flatbuf --iter-mode index --loops $2 --strlen $3 --ccts $i
258 done
259
260 prepare_res iter_ropes_iter.out iter_ropes_iter ropes_iter
261 if $verbose; then
262 echo "Ropes by iterator :"
263 fi
264 for i in `seq 1 "$1"`; do
265 if $verbose; then
266 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
267 fi
268 bench_command $i ropes_iter$i ./iteration_bench -m ropestr --iter-mode iterator --loops $2 --strlen $3 --ccts $i
269 done
270
271 prepare_res iter_ropes_index.out iter_ropes_index ropes_index
272 if $verbose; then
273 echo "Ropes by index :"
274 fi
275 for i in `seq 1 "$1"`; do
276 if $verbose; then
277 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
278 fi
279 bench_command $i ropes_index$i ./iteration_bench -m ropestr --iter-mode index --loops $2 --strlen $3 --ccts $i
280 done
281
282 prepare_res iter_buf_ropes_iter.out iter_buf_ropes_iter buf_ropes_iter
283 if $verbose; then
284 echo "RopeBuffer by iterator :"
285 fi
286 for i in `seq 1 "$1"`; do
287 if $verbose; then
288 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
289 fi
290 bench_command $i buf_ropes_iter$i ./iteration_bench -m ropebuf --iter-mode iterator --loops $2 --strlen $3 --ccts $i
291 done
292
293 prepare_res iter_buf_ropes_index.out iter_buf_ropes_index buf_ropes_index
294 if $verbose; then
295 echo "RopeBuffer by index :"
296 fi
297 for i in `seq 1 "$1"`; do
298 if $verbose; then
299 echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
300 fi
301 bench_command $i buf_ropes_index$i ./iteration_bench -m ropebuf --iter-mode index --loops $2 --strlen $3 --ccts $i
302 done
303
304 plot iter.gnu
305
306 cd ..
307 }
308
309 function bench_substr()
310 {
311 if [ -d string_substr ]; then
312 rm string_substr/*
313 else
314 mkdir string_substr
315 fi
316 cd string_substr
317
318 if $verbose; then
319 echo "*** Benching substring performance ***"
320 fi
321
322 ../../../bin/nitc --global ../substr_bench.nit
323
324 prepare_res substr_flat.out substr_flat flatstring
325 if $verbose; then
326 echo "FlatStrings :"
327 fi
328 for i in `seq 1 "$1"`; do
329 if $verbose; then
330 echo "String length = $i, loops = $2, Loops = $3"
331 fi
332 bench_command $i flatstring$i ./substr_bench -m flatstr --loops $2 --strlen $3 --ccts $i
333 done
334
335 prepare_res substr_buf.out substr_buf flatbuffer
336 if $verbose; then
337 echo "FlatBuffers :"
338 fi
339 for i in `seq 1 "$1"`; do
340 if $verbose; then
341 echo "String length = $i, loops = $2, Loops = $3"
342 fi
343 bench_command $i flatbuffer$i ./substr_bench -m flatbuf --loops $2 --strlen $3 --ccts $i
344 done
345
346 prepare_res substr_ropes.out substr_ropes ropes
347 if $verbose; then
348 echo "Ropes :"
349 fi
350 for i in `seq 1 "$1"`; do
351 if $verbose; then
352 echo "String length = $i, loops = $2, Loops = $3"
353 fi
354 bench_command $i ropes$i ./substr_bench -m ropestr --loops $2 --strlen $3 --ccts $i
355 done
356
357 prepare_res substr_buf_ropes.out substr_buf_ropes buf_ropes
358 if $verbose; then
359 echo "RopeBuffers :"
360 fi
361 for i in `seq 1 "$1"`; do
362 if $verbose; then
363 echo "String length = $i, loops = $2, Loops = $3"
364 fi
365 bench_command $i buf_ropes$i ./substr_bench -m ropebuf --loops $2 --strlen $3 --ccts $i
366 done
367
368 plot substr.gnu
369
370 cd ..
371 }
372
373 stop=false
374 while [ "$stop" = false ]; do
375 case "$1" in
376 -v) verbose=true; shift;;
377 -h) usage; exit;;
378 -n) count="$2"; shift; shift;;
379 *) stop=true
380 esac
381 done
382
383 if test $# -ne 4; then
384 usage
385 exit
386 fi
387
388 case "$1" in
389 iter) shift; bench_iteration $@ ;;
390 cct) shift; bench_concat $@ ;;
391 substr) shift; bench_substr $@ ;;
392 array) shift; bench_array $@ ;;
393 *) usage; exit;;
394 esac