1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
11 # Benches for iteration on variants of Text
12 module utf_iteration_bench
15 import string_experimentations
::utf8_noindex
17 fun bench_flatstr_iter
(nb_cct
: Int, loops
: Int, strlen
: Int)
20 var x
= a
.as(FlatString)
21 for i
in [0 .. nb_cct
] do x
= (x
+ a
).as(FlatString)
25 var it
= new FlatStringIter(x
)
33 fun bench_flatstr_index
(nb_cct
: Int, loops
: Int, strlen
: Int)
36 var x
= a
.as(FlatString)
37 for i
in [0 .. nb_cct
] do x
= (x
+ a
).as(FlatString)
43 while pos
< x
.length
do
51 var opts
= new OptionContext
52 var access_mode
= new OptionEnum(["iterator", "index"], "Iteration mode", -1, "--iter-mode")
53 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")
54 var loops
= new OptionInt("Number of loops to be done", -1, "--loops")
55 var strlen
= new OptionInt("Length of the base string", -1, "--strlen")
56 opts
.add_option
(nb_ccts
, loops
, strlen
, access_mode
)
60 if nb_ccts
.value
== -1 or loops
.value
== -1 or strlen
.value
== -1 then
65 var iterval
= access_mode
.value
68 bench_flatstr_iter
(nb_ccts
.value
, loops
.value
, strlen
.value
)
69 else if iterval
== 1 then
70 bench_flatstr_index
(nb_ccts
.value
, loops
.value
, strlen
.value
)