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 iteration_bench
16 fun bench_flatstr_iter
(nb_cct
: Int, loops
: Int, strlen
: Int)
20 for i
in [0 .. nb_cct
] do x
+= a
31 fun bench_flatstr_index
(nb_cct
: Int, loops
: Int, strlen
: Int)
35 for i
in [0 .. nb_cct
] do x
+= a
41 while pos
< x
.length
do
49 fun bench_flatbuf_iter
(nb_cct
: Int, loops
: Int, strlen
: Int)
52 var x
= new FlatBuffer.from
(a
)
53 for i
in [0 .. nb_cct
] do x
.append a
64 fun bench_flatbuf_index
(nb_cct
: Int, loops
: Int, strlen
: Int)
67 var x
= new FlatBuffer.from
(a
)
68 for i
in [0 .. nb_cct
] do x
.append a
74 while pos
< x
.length
do
82 var opts
= new OptionContext
83 var mode
= new OptionEnum(["flatstr", "flatbuf"], "Mode", -1, "-m")
84 var access_mode
= new OptionEnum(["iterator", "index"], "Iteration mode", -1, "--iter-mode")
85 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")
86 var loops
= new OptionInt("Number of loops to be done", -1, "--loops")
87 var strlen
= new OptionInt("Length of the base string", -1, "--strlen")
88 opts
.add_option
(mode
, nb_ccts
, loops
, strlen
, access_mode
)
92 if nb_ccts
.value
== -1 or loops
.value
== -1 or strlen
.value
== -1 then
97 var modval
= mode
.value
98 var iterval
= access_mode
.value
102 bench_flatstr_iter
(nb_ccts
.value
, loops
.value
, strlen
.value
)
103 else if iterval
== 1 then
104 bench_flatstr_index
(nb_ccts
.value
, loops
.value
, strlen
.value
)
109 else if modval
== 1 then
111 bench_flatbuf_iter
(nb_ccts
.value
, loops
.value
, strlen
.value
)
112 else if iterval
== 1 then
113 bench_flatbuf_index
(nb_ccts
.value
, loops
.value
, strlen
.value
)