X-Git-Url: http://nitlanguage.org diff --git a/benchmarks/strings/substr_bench.nit b/benchmarks/strings/substr_bench.nit index effb9ec..3727960 100644 --- a/benchmarks/strings/substr_bench.nit +++ b/benchmarks/strings/substr_bench.nit @@ -12,15 +12,16 @@ module substr_bench import opts +intrude import standard::ropes fun bench_flatstr(nb_cct: Int, loops: Int, strlen: Int) do var a = "a" * strlen - var x = a - for i in [0 .. nb_cct] do x += a + a = a * nb_cct + 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 @@ -28,17 +29,44 @@ end fun bench_flatbuf(nb_cct: Int, loops: Int, strlen: Int) do var a = "a" * strlen + a = a * nb_cct + var maxl = a.length - 1 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 + +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 cnt = 0 + while cnt != loops do + x.substring(maxl.rand, maxl.rand) cnt += 1 end end var opts = new OptionContext -var mode = new OptionEnum(["flatstr", "flatbuf"], "Mode", -1, "-m") +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 loops = new OptionInt("Number of loops to be done", -1, "--loops") var strlen = new OptionInt("Length of the base string", -1, "--strlen") @@ -52,11 +80,16 @@ if nb_ccts.value == -1 or loops.value == -1 or strlen.value == -1 then end var modval = mode.value +srand_from(0) if modval == 0 then bench_flatstr(nb_ccts.value, 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) else opts.usage exit(-1)