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 # Benchmark on the Array.to_s function using several methods.
16 fun bench_array
(arr_size
, item_size
, loops
: Int)
18 var arr
= new Array[String].with_capacity
(arr_size
)
19 var s
= "a" * item_size
21 for i
in [0 .. arr_size
[ do arr
.push s
23 for i
in [0..loops
[ do
28 var opts
= new OptionContext
29 var nb_ccts
= new OptionInt("Size of an element", -1, "--ccts")
30 var loops
= new OptionInt("Number of loops to be done", -1, "--loops")
31 var strlen
= new OptionInt("Length of the Array", -1, "--strlen")
32 opts
.add_option
(nb_ccts
, loops
, strlen
)
36 if nb_ccts
.value
== -1 or loops
.value
== -1 or strlen
.value
== -1 then
41 bench_array
(strlen
.value
, nb_ccts
.value
, loops
.value
)