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
15 intrude import standard
::ropes
20 return new Concat(self, s
)
24 redef class FlatString
27 var b
= new FlatBuffer.with_capacity
(length
+ s
.length
)
29 for i
in s
.substrings
do b
.append i
34 fun bench_flatstr_iter
(nb_cct
: Int, loops
: Int, strlen
: Int)
48 fun bench_flatstr_index
(nb_cct
: Int, loops
: Int, strlen
: Int)
57 while pos
< a
.length
do
65 fun bench_ropestr_iter
(nb_cct
: Int, loops
: Int, strlen
: Int)
68 var x
: String = new Concat(a
, a
)
69 for i
in [2 .. nb_cct
[ do x
= new Concat(x
, a
)
80 fun bench_ropestr_index
(nb_cct
: Int, loops
: Int, strlen
: Int)
83 var x
: String = new Concat(a
, a
)
84 for i
in [2 .. nb_cct
[ do x
= new Concat(x
, a
)
90 while pos
< x
.length
do
98 fun bench_flatbuf_iter
(nb_cct
: Int, loops
: Int, strlen
: Int)
102 var x
= new FlatBuffer.from
(a
)
105 while cnt
!= loops
do
113 fun bench_flatbuf_index
(nb_cct
: Int, loops
: Int, strlen
: Int)
117 var x
= new FlatBuffer.from
(a
)
121 while cnt
!= loops
do
123 while pos
< x
.length
do
131 fun bench_ropebuf_iter
(nb_cct
: Int, loops
: Int, strlen
: Int)
134 var x
= new RopeBuffer.from
(a
)
135 for i
in [0 .. nb_cct
[ do x
.append a
138 while cnt
!= loops
do
146 fun bench_ropebuf_index
(nb_cct
: Int, loops
: Int, strlen
: Int)
149 var x
= new RopeBuffer.from
(a
)
150 for i
in [0 .. nb_cct
[ do x
.append a
154 while cnt
!= loops
do
156 while pos
< x
.length
do
164 var opts
= new OptionContext
165 var mode
= new OptionEnum(["flatstr", "flatbuf", "ropestr", "ropebuf"], "Mode", -1, "-m")
166 var access_mode
= new OptionEnum(["iterator", "index"], "Iteration mode", -1, "--iter-mode")
167 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")
168 var loops
= new OptionInt("Number of loops to be done", -1, "--loops")
169 var strlen
= new OptionInt("Length of the base string", -1, "--strlen")
170 opts
.add_option
(mode
, nb_ccts
, loops
, strlen
, access_mode
)
174 if nb_ccts
.value
== -1 or loops
.value
== -1 or strlen
.value
== -1 then
179 var modval
= mode
.value
180 var iterval
= access_mode
.value
184 bench_flatstr_iter
(nb_ccts
.value
, loops
.value
, strlen
.value
)
185 else if iterval
== 1 then
186 bench_flatstr_index
(nb_ccts
.value
, loops
.value
, strlen
.value
)
191 else if modval
== 1 then
193 bench_flatbuf_iter
(nb_ccts
.value
, loops
.value
, strlen
.value
)
194 else if iterval
== 1 then
195 bench_flatbuf_index
(nb_ccts
.value
, loops
.value
, strlen
.value
)
200 else if modval
== 2 then
202 bench_ropestr_iter
(nb_ccts
.value
, loops
.value
, strlen
.value
)
203 else if iterval
== 1 then
204 bench_ropestr_index
(nb_ccts
.value
, loops
.value
, strlen
.value
)
209 else if modval
== 3 then
211 bench_ropebuf_iter
(nb_ccts
.value
, loops
.value
, strlen
.value
)
212 else if iterval
== 1 then
213 bench_ropebuf_index
(nb_ccts
.value
, loops
.value
, strlen
.value
)