# Benches on the substring operation on variants of Text
module substr_bench
+import bench_base
import opts
-fun bench_rope(nb_cct: Int, loops: Int, strlen: Int)
+private fun bench_string(loops: Int, strlen: Int)
do
- var a = "a" * strlen
- var x:String = new RopeString.from(a)
- for i in [0 .. nb_cct] do x += a
+ var a = prepare_string(strlen)
+ var maxl = a.length - 1
var cnt = 0
while cnt != loops do
- x.substring(0,5)
+ a.substring(maxl.rand, maxl.rand)
cnt += 1
end
end
-fun bench_flatstr(nb_cct: Int, loops: Int, strlen: Int)
+private fun bench_buffer(loops: Int, strlen: Int)
do
- var a = "a" * strlen
- var x = a
- for i in [0 .. nb_cct] do x += a
+ var x = prepare_buffer(strlen)
+ var maxl = x.length
var cnt = 0
while cnt != loops do
- x.substring(0,5)
- cnt += 1
- end
-end
-
-fun bench_flatbuf(nb_cct: Int, loops: Int, strlen: Int)
-do
- var a = "a" * strlen
- var x = new FlatBuffer.from(a)
- for i in [0 .. nb_cct] do x.append a
- var cnt = 0
- while cnt != loops do
- x.substring(0,5)
+ x.substring(maxl.rand, maxl.rand)
cnt += 1
end
end
var opts = new OptionContext
-var mode = new OptionEnum(["rope", "flatstr", "flatbuf"], "Mode", -1, "-m")
-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")
+var mode = new OptionEnum(["string", "buffer"], "Mode", -1, "-m")
var loops = new OptionInt("Number of loops to be done", -1, "--loops")
var strlen = new OptionInt("Length of the base string", -1, "--strlen")
-opts.add_option(mode, nb_ccts, loops, strlen)
+opts.add_option(mode, loops, strlen)
opts.parse(args)
-if nb_ccts.value == -1 or loops.value == -1 or strlen.value == -1 then
+if loops.value == -1 or strlen.value == -1 then
opts.usage
exit(-1)
end
var modval = mode.value
+srand_from(0)
if modval == 0 then
- bench_rope(nb_ccts.value, loops.value, strlen.value)
+ bench_string(loops.value, strlen.value)
else if modval == 1 then
- bench_flatstr(nb_ccts.value, loops.value, strlen.value)
-else if modval == 2 then
- bench_flatbuf(nb_ccts.value, loops.value, strlen.value)
+ bench_buffer(loops.value, strlen.value)
else
opts.usage
exit(-1)