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
17 private fun bench_string_iter
(loops
: Int, strlen
: Int)
19 var a
= prepare_string
(strlen
)
30 private fun bench_string_index
(loops
: Int, strlen
: Int)
32 var a
= prepare_string
(strlen
)
38 while pos
< a
.length
do
46 private fun bench_buffer_iter
(loops
: Int, strlen
: Int)
48 var x
= prepare_buffer
(strlen
)
59 private fun bench_buffer_index
(loops
: Int, strlen
: Int)
61 var x
= prepare_buffer
(strlen
)
67 while pos
< x
.length
do
75 var opts
= new OptionContext
76 var mode
= new OptionEnum(["string", "buffer"], "Mode", -1, "-m")
77 var access_mode
= new OptionEnum(["iterator", "index"], "Iteration mode", -1, "--iter-mode")
78 var loops
= new OptionInt("Number of loops to be done", -1, "--loops")
79 var strlen
= new OptionInt("Length of the base string", -1, "--strlen")
80 opts
.add_option
(mode
, loops
, strlen
, access_mode
)
84 if loops
.value
== -1 or strlen
.value
== -1 then
89 var modval
= mode
.value
90 var iterval
= access_mode
.value
94 bench_string_iter
(loops
.value
, strlen
.value
)
95 else if iterval
== 1 then
96 bench_string_index
(loops
.value
, strlen
.value
)
101 else if modval
== 1 then
103 bench_buffer_iter
(loops
.value
, strlen
.value
)
104 else if iterval
== 1 then
105 bench_buffer_index
(loops
.value
, strlen
.value
)