benchs/strings: Update string basic functions benchmarks
[nit.git] / benchmarks / strings / substr_bench.nit
index 4121f7f..c1382ef 100644 (file)
 # Benches on the substring operation on variants of Text
 module substr_bench
 
+import bench_base
 import opts
-intrude import standard::text::ropes
 
-fun bench_flatstr(nb_cct: Int, loops: Int, strlen: Int)
+private fun bench_string(loops: Int, strlen: Int)
 do
-       var a = "a" * strlen
-       a = a * nb_cct
+       var a = prepare_string(strlen)
        var maxl = a.length - 1
        var cnt = 0
        while cnt != loops do
@@ -26,38 +25,10 @@ do
        end
 end
 
-fun bench_flatbuf(nb_cct: Int, loops: Int, strlen: Int)
+private fun bench_buffer(loops: Int, strlen: Int)
 do
-       var a = "a" * strlen
-       a = a * nb_cct
-       var maxl = a.length - 1
-       var x = new FlatBuffer.from(a)
-       var cnt = 0
-       while cnt != loops do
-               x.substring(maxl.rand, maxl.rand)
-               cnt += 1
-       end
-end
-
-fun bench_ropestr(nb_cct: Int, loops: Int, strlen: Int)
-do
-       var a = "a" * strlen
-       var x = new Concat(a, a)
-       for i in [2 .. nb_cct[ do x = new Concat(x, a)
-       var maxl = x.length - 1
-       var cnt = 0
-       while cnt != loops do
-               x.substring(maxl.rand, maxl.rand)
-               cnt += 1
-       end
-end
-
-fun bench_ropebuf(nb_cct: Int, loops: Int, strlen: Int)
-do
-       var a = "a" * strlen
-       var x = new RopeBuffer.from(a)
-       for i in [1 .. nb_cct[ do x.append a
-       var maxl = x.length - 1
+       var x = prepare_buffer(strlen)
+       var maxl = x.length
        var cnt = 0
        while cnt != loops do
                x.substring(maxl.rand, maxl.rand)
@@ -66,15 +37,14 @@ do
 end
 
 var opts = new OptionContext
-var mode = new OptionEnum(["flatstr", "flatbuf", "ropestr", "ropebuf"], "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
@@ -83,13 +53,9 @@ var modval = mode.value
 srand_from(0)
 
 if modval == 0 then
-       bench_flatstr(nb_ccts.value, loops.value, strlen.value)
+       bench_string(loops.value, strlen.value)
 else if modval == 1 then
-       bench_flatbuf(nb_ccts.value, loops.value, strlen.value)
-else if modval == 2 then
-       bench_ropestr(nb_ccts.value, loops.value, strlen.value)
-else if modval == 3 then
-       bench_ropebuf(nb_ccts.value, loops.value, strlen.value)
+       bench_buffer(loops.value, strlen.value)
 else
        opts.usage
        exit(-1)