7d71a8bfc3137acbfb59e37d2941d5e5d77043d2
[nit.git] / benchmarks / strings / utf_substr_bench.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 # Benches on the substring operation on variants of Text
12 module utf_substr_bench
13
14 import opts
15 import string_experimentations::utf8_noindex
16
17 fun bench_flatstr(nb_cct: Int, loops: Int, strlen: Int)
18 do
19 var a = "a" * strlen
20 var x = a
21 for i in [0 .. nb_cct] do x += a
22 var cnt = 0
23 while cnt != loops do
24 x.substring(0,5)
25 cnt += 1
26 end
27 end
28
29 var opts = new OptionContext
30 var nb_ccts = new OptionInt("Number of concatenations done to the string (in the case of the rope, this will increase its depth)", -1, "--ccts")
31 var loops = new OptionInt("Number of loops to be done", -1, "--loops")
32 var strlen = new OptionInt("Length of the base string", -1, "--strlen")
33 opts.add_option(nb_ccts, loops, strlen)
34
35 opts.parse(args)
36
37 if nb_ccts.value == -1 or loops.value == -1 or strlen.value == -1 then
38 opts.usage
39 exit(-1)
40 end
41
42 bench_flatstr(nb_ccts.value, loops.value, strlen.value)