benchs/strings: Update string basic functions benchmarks
[nit.git] / benchmarks / strings / bench_base.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
9 # another product.
10
11 # Base facilities for String-related microbenchmarks
12 module bench_base
13
14 # Prepares a string to be used in a bench
15 fun prepare_string(strlen: Int): String do
16 var s = "a"
17 for i in [1 .. strlen[ do s += "a"
18 return s
19 end
20
21 # Prepares a buffer to be used in a bench
22 fun prepare_buffer(strlen: Int): Buffer do
23 var b = new Buffer
24 for i in [0 .. strlen[ do b.add 'a'
25 return b
26 end