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 on the substring operation on variants of Text
15 intrude import standard
::ropes
17 fun bench_flatstr
(nb_cct
: Int, loops
: Int, strlen
: Int)
21 var maxl
= a
.length
- 1
24 a
.substring
(maxl
.rand
, maxl
.rand
)
29 fun bench_flatbuf
(nb_cct
: Int, loops
: Int, strlen
: Int)
33 var maxl
= a
.length
- 1
34 var x
= new FlatBuffer.from
(a
)
37 x
.substring
(maxl
.rand
, maxl
.rand
)
42 fun bench_ropestr
(nb_cct
: Int, loops
: Int, strlen
: Int)
45 var x
= new Concat(a
, a
)
46 for i
in [2 .. nb_cct
[ do x
= new Concat(x
, a
)
47 var maxl
= x
.length
- 1
50 x
.substring
(maxl
.rand
, maxl
.rand
)
55 fun bench_ropebuf
(nb_cct
: Int, loops
: Int, strlen
: Int)
58 var x
= new RopeBuffer.from
(a
)
59 for i
in [1 .. nb_cct
[ do x
.append a
60 var maxl
= x
.length
- 1
63 x
.substring
(maxl
.rand
, maxl
.rand
)
68 var opts
= new OptionContext
69 var mode
= new OptionEnum(["flatstr", "flatbuf", "ropestr", "ropebuf"], "Mode", -1, "-m")
70 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")
71 var loops
= new OptionInt("Number of loops to be done", -1, "--loops")
72 var strlen
= new OptionInt("Length of the base string", -1, "--strlen")
73 opts
.add_option
(mode
, nb_ccts
, loops
, strlen
)
77 if nb_ccts
.value
== -1 or loops
.value
== -1 or strlen
.value
== -1 then
82 var modval
= mode
.value
86 bench_flatstr
(nb_ccts
.value
, loops
.value
, strlen
.value
)
87 else if modval
== 1 then
88 bench_flatbuf
(nb_ccts
.value
, loops
.value
, strlen
.value
)
89 else if modval
== 2 then
90 bench_ropestr
(nb_ccts
.value
, loops
.value
, strlen
.value
)
91 else if modval
== 3 then
92 bench_ropebuf
(nb_ccts
.value
, loops
.value
, strlen
.value
)