X-Git-Url: http://nitlanguage.org diff --git a/benchmarks/strings/iteration_bench.nit b/benchmarks/strings/iteration_bench.nit index a8047d2..ea70338 100644 --- a/benchmarks/strings/iteration_bench.nit +++ b/benchmarks/strings/iteration_bench.nit @@ -12,78 +12,40 @@ module iteration_bench import opts +import bench_base -fun bench_rope_iter(nb_cct: Int, loops: Int, strlen: Int) +private fun bench_string_iter(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 cnt = 0 var c: Char while cnt != loops do - for i in x do - c = i - end - cnt += 1 - end -end - -fun bench_rope_index(nb_cct: Int, 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 cnt = 0 - var c: Char - var pos = 0 - while cnt != loops do - pos = 0 - while pos < x.length do - c = x[pos] - pos += 1 - end - cnt += 1 - end -end - -fun bench_flatstr_iter(nb_cct: Int, loops: Int, strlen: Int) -do - var a = "a" * strlen - var x = a - for i in [0 .. nb_cct] do x += a - var cnt = 0 - var c: Char - while cnt != loops do - for i in x do + for i in a do c = i end cnt += 1 end end -fun bench_flatstr_index(nb_cct: Int, loops: Int, strlen: Int) +private fun bench_string_index(loops: Int, strlen: Int) do - var a = "a" * strlen - var x = a - for i in [0 .. nb_cct] do x += a + var a = prepare_string(strlen) var cnt = 0 var c: Char var pos = 0 while cnt != loops do pos = 0 - while pos < x.length do - c = x[pos] + while pos < a.length do + c = a[pos] pos += 1 end cnt += 1 end end -fun bench_flatbuf_iter(nb_cct: Int, loops: Int, strlen: Int) +private fun bench_buffer_iter(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 x = prepare_buffer(strlen) var cnt = 0 var c: Char while cnt != loops do @@ -94,11 +56,9 @@ do end end -fun bench_flatbuf_index(nb_cct: Int, loops: Int, strlen: Int) +private fun bench_buffer_index(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 x = prepare_buffer(strlen) var cnt = 0 var c: Char var pos = 0 @@ -113,16 +73,15 @@ do end var opts = new OptionContext -var mode = new OptionEnum(["rope", "flatstr", "flatbuf"], "Mode", -1, "-m") +var mode = new OptionEnum(["string", "buffer"], "Mode", -1, "-m") var access_mode = new OptionEnum(["iterator", "index"], "Iteration mode", -1, "--iter-mode") -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") -opts.add_option(mode, nb_ccts, loops, strlen, access_mode) +opts.add_option(mode, loops, strlen, access_mode) 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 @@ -132,27 +91,18 @@ var iterval = access_mode.value if modval == 0 then if iterval == 0 then - bench_rope_iter(nb_ccts.value, loops.value, strlen.value) + bench_string_iter(loops.value, strlen.value) else if iterval == 1 then - bench_rope_index(nb_ccts.value, loops.value, strlen.value) + bench_string_index(loops.value, strlen.value) else opts.usage exit(-1) end else if modval == 1 then if iterval == 0 then - bench_flatstr_iter(nb_ccts.value, loops.value, strlen.value) - else if iterval == 1 then - bench_flatstr_index(nb_ccts.value, loops.value, strlen.value) - else - opts.usage - exit(-1) - end -else if modval == 2 then - if iterval == 0 then - bench_flatbuf_iter(nb_ccts.value, loops.value, strlen.value) + bench_buffer_iter(loops.value, strlen.value) else if iterval == 1 then - bench_flatbuf_index(nb_ccts.value, loops.value, strlen.value) + bench_buffer_index(loops.value, strlen.value) else opts.usage exit(-1)