benchmarks/strings: Adapted for new Ropes.
authorLucas Bajolet <r4pass@hotmail.com>
Mon, 8 Sep 2014 14:16:14 +0000 (10:16 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Thu, 6 Nov 2014 19:20:10 +0000 (14:20 -0500)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

benchmarks/bench_strings.sh
benchmarks/strings/chain_concat.nit
benchmarks/strings/iteration_bench.nit
benchmarks/strings/substr_bench.nit

index c327d58..0bb13a7 100755 (executable)
@@ -54,7 +54,7 @@ function bench_array()
                echo "*** Benching Array.to_s performance ***"
        fi
 
-       ../bin/nitg --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_rope.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+       ../bin/nitg --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_flatstr.nit -m ../lib/standard/ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
 
        prepare_res arr_tos_ropes.out arr_tos_ropes ropes
        if $verbose; then
@@ -67,6 +67,19 @@ function bench_array()
                bench_command $i ropes$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
        done
 
+       ../bin/nitg --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_flatstr.nit -m ../lib/standard/ropes.nit -m ../lib/buffered_ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+
+       prepare_res arr_tos_buf_ropes.out arr_tos_buf_ropes buffered_ropes
+       if $verbose; then
+               echo "Buffered Ropes :"
+       fi
+       for i in `seq 1 "$3"`; do
+               if $verbose; then
+                       echo "String length = $i, Concats/loop = $1, Loops = $2"
+               fi
+               bench_command $i buf_ropes$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
+       done
+
        ../bin/nitg --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_flatstr.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
 
        prepare_res arr_tos_flat.out arr_tos_flat flatstring
@@ -110,7 +123,7 @@ function bench_array()
 
        prepare_res arr_tos_man_buf.out arr_tos_man_buf flatbuf_with_capacity
        if $verbose; then
-               echo "Memmove :"
+               echo "FlatBuffer.with_capacity :"
        fi
        for i in `seq 1 "$3"`; do
                if $verbose; then
@@ -119,25 +132,30 @@ function bench_array()
                bench_command $i flatbuf_with_capacity$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
        done
 
+       ../bin/nitg --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_rope_buf.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+
+       prepare_res arr_tos_rope_buf.out arr_tos_rope_buf ropebuf
+       if $verbose; then
+               echo "RopeBuffer :"
+       fi
+       for i in `seq 1 "$3"`; do
+               if $verbose; then
+                       echo "String length = $i, Concats/loop = $1, Loops = $2"
+               fi
+               bench_command $i ropebuf$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
+       done
+
        plot array_tos.gnu
 }
 
 function bench_concat()
 {
-       if $verbose; then
-               echo "*** Benching concat performance ***"
-       fi
+       ../bin/nitg --global ./strings/chain_concat.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+       ../bin/nitg --global ./strings/utf_chain_concat.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
 
-       prepare_res concat_ropes.out concat_ropes ropes
        if $verbose; then
-               echo "Ropes :"
+               echo "*** Benching concat performance ***"
        fi
-       for i in `seq 1 "$1"`; do
-               if $verbose; then
-                       echo "String length = $i, Concats/loop = $2, Loops = $3"
-               fi
-               bench_command $i ropes$i ./chain_concat -m rope --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
-       done
 
        prepare_res concat_flat.out concat_flat flatstring
        if $verbose; then
@@ -172,37 +190,57 @@ function bench_concat()
                bench_command $i flatstr_utf8_noindex$i ./utf_chain_concat -m flatstr_utf8_noindex --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
        done
 
-       plot concat.gnu
-}
+       ../bin/nitg --global ./strings/chain_concat.nit -m ../lib/standard/ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
 
-function bench_iteration()
-{
+       prepare_res concat_ropes.out concat_ropes ropes
        if $verbose; then
-               echo "*** Benching iteration performance ***"
+               echo "Ropes :"
        fi
+       for i in `seq 1 "$1"`; do
+               if $verbose; then
+                       echo "String length = $i, Concats/loop = $2, Loops = $3"
+               fi
+               bench_command $i ropes$i ./chain_concat -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+       done
 
-       prepare_res iter_ropes_iter.out iter_ropes_iter ropes_iter
+       ../bin/nitg --global ./strings/chain_concat.nit -m ../lib/standard/ropes.nit -m ../lib/buffered_ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+
+       prepare_res concat_buf_ropes.out concat_buf_ropes buffered_ropes
        if $verbose; then
-               echo "Ropes by iterator :"
+               echo "buffered ropes :"
        fi
        for i in `seq 1 "$1"`; do
                if $verbose; then
-                       echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
+                       echo "string length = $i, concats/loop = $2, loops = $3"
                fi
-               bench_command $i ropes_iter$i ./iteration_bench -m rope --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i buf_ropes$i ./chain_concat -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
        done
 
-       prepare_res iter_ropes_index.out iter_ropes_index ropes_index
+       ../bin/nitg --global ./strings/chain_cct_ropebuf.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+
+       prepare_res cct_buf_ropes.out cct_buf_ropes cctbuf_ropes
        if $verbose; then
-               echo "Ropes by index :"
+               echo "buffered ropes :"
        fi
        for i in `seq 1 "$1"`; do
                if $verbose; then
-                       echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
+                       echo "string length = $i, concats/loop = $2, loops = $3"
                fi
-               bench_command $i ropes_index$i ./iteration_bench -m rope --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i cctbuf_ropes$i ./chain_cct_ropebuf --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
        done
 
+       plot concat.gnu
+}
+
+function bench_iteration()
+{
+       if $verbose; then
+               echo "*** Benching iteration performance ***"
+       fi
+
+       ../bin/nitg --global ./strings/iteration_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+       ../bin/nitg --global ./strings/utf_iteration_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+
        prepare_res iter_flat_iter.out iter_flat_iter flatstring_iter
        if $verbose; then
                echo "FlatStrings by iterator :"
@@ -269,26 +307,66 @@ function bench_iteration()
                bench_command $i flatstr_index_utf8_noindex$i ./utf_iteration_bench -m flatstr_utf8_noindex --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
        done
 
-       plot iter.gnu
-}
+       ../bin/nitg --global ./strings/iteration_bench.nit -m ../lib/standard/ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
 
-function bench_substr()
-{
+       prepare_res iter_ropes_iter.out iter_ropes_iter ropes_iter
        if $verbose; then
-               echo "*** Benching substring performance ***"
+               echo "Ropes by iterator :"
        fi
+       for i in `seq 1 "$1"`; do
+               if $verbose; then
+                       echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
+               fi
+               bench_command $i ropes_iter$i ./iteration_bench -m flatstr --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+       done
 
-       prepare_res substr_ropes.out substr_ropes ropes
+       prepare_res iter_ropes_index.out iter_ropes_index ropes_index
        if $verbose; then
-               echo "Ropes :"
+               echo "Ropes by index :"
        fi
        for i in `seq 1 "$1"`; do
                if $verbose; then
-                       echo "String length = $i, loops = $2, Loops = $3"
+                       echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
+               fi
+               bench_command $i ropes_index$i ./iteration_bench -m flatstr --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+       done
+
+       ../bin/nitg --global ./strings/iteration_bench.nit -m ../lib/standard/ropes.nit -m ../lib/buffered_ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+
+       prepare_res iter_buf_ropes_iter.out iter_buf_ropes_iter buf_ropes_iter
+       if $verbose; then
+               echo "Buffered Ropes by iterator :"
+       fi
+       for i in `seq 1 "$1"`; do
+               if $verbose; then
+                       echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
+               fi
+               bench_command $i buf_ropes_iter$i ./iteration_bench -m flatstr --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+       done
+
+       prepare_res iter_buf_ropes_index.out iter_buf_ropes_index buf_ropes_index
+       if $verbose; then
+               echo "Buffered Ropes by index :"
+       fi
+       for i in `seq 1 "$1"`; do
+               if $verbose; then
+                       echo "String base length = $1, Concats (depth of the rope) = $i, Loops = $3"
                fi
-               bench_command $i ropes$i ./substr_bench -m rope --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i buf_ropes_index$i ./iteration_bench -m flatstr --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
        done
 
+       plot iter.gnu
+}
+
+function bench_substr()
+{
+       if $verbose; then
+               echo "*** Benching substring performance ***"
+       fi
+
+       ../bin/nitg --global ./strings/substr_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+       ../bin/nitg --global ./strings/utf_substr_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+
        prepare_res substr_flat.out substr_flat flatstring
        if $verbose; then
                echo "FlatStrings :"
@@ -322,6 +400,31 @@ function bench_substr()
                bench_command $i flatstring_utf8_noindex$i ./utf_substr_bench -m flatstr_utf8_noindex --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
        done
 
+       ../bin/nitg --global ./strings/substr_bench.nit -m ../lib/standard/ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+
+       prepare_res substr_ropes.out substr_ropes ropes
+       if $verbose; then
+               echo "Ropes :"
+       fi
+       for i in `seq 1 "$1"`; do
+               if $verbose; then
+                       echo "String length = $i, loops = $2, Loops = $3"
+               fi
+               bench_command $i ropes$i ./substr_bench -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+       done
+
+       ../bin/nitg --global ./strings/substr_bench.nit -m ../lib/standard/ropes.nit -m ../lib/buffered_ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+
+       prepare_res substr_buf_ropes.out substr_buf_ropes buf_ropes
+       if $verbose; then
+               echo "Buffered Ropes :"
+       fi
+       for i in `seq 1 "$1"`; do
+               if $verbose; then
+                       echo "String length = $i, loops = $2, Loops = $3"
+               fi
+               bench_command $i buf_ropes$i ./substr_bench -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+       done
        plot substr.gnu
 }
 
@@ -340,17 +443,6 @@ if test $# -ne 4; then
        exit
 fi
 
-if $verbose; then
-       echo "Compiling"
-fi
-
-../bin/nitg --global ./strings/chain_concat.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
-../bin/nitg --global ./strings/utf_chain_concat.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
-../bin/nitg --global ./strings/iteration_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
-../bin/nitg --global ./strings/utf_iteration_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
-../bin/nitg --global ./strings/substr_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
-../bin/nitg --global ./strings/utf_substr_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
-
 case "$1" in
        iter) shift; bench_iteration $@ ;;
        cct) shift; bench_concat $@ ;;
index 35466f9..a45075f 100644 (file)
@@ -25,18 +25,6 @@ do
        end
 end
 
-fun bench_rope(str_size: Int, nb_ccts: Int, loops: Int)
-do
-       var lft = "a" * str_size
-
-       for i in [0..loops] do
-               var str: String = new RopeString.from(lft)
-               for j in [0..nb_ccts] do
-                       str += lft
-               end
-       end
-end
-
 fun bench_flatbuf(str_size: Int, nb_ccts: Int, loops: Int)
 do
        var lft = "a" * str_size
@@ -51,7 +39,7 @@ do
 end
 
 var opts = new OptionContext
-var mode = new OptionEnum(["rope", "flatstr", "flatbuf"], "Mode", -1, "-m")
+var mode = new OptionEnum(["flatstr", "flatbuf"], "Mode", -1, "-m")
 var nb_ccts = new OptionInt("Number of concatenations per loop", -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")
@@ -67,10 +55,8 @@ end
 var modval = mode.value
 
 if modval == 0 then
-       bench_rope(strlen.value, nb_ccts.value, loops.value)
-else if modval == 1 then
        bench_flatstr(strlen.value, nb_ccts.value, loops.value)
-else if modval == 2 then
+else if modval == 1 then
        bench_flatbuf(strlen.value, nb_ccts.value, loops.value)
 else
        opts.usage
index a8047d2..0e36c49 100644 (file)
@@ -13,39 +13,6 @@ module iteration_bench
 
 import opts
 
-fun bench_rope_iter(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
-       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
@@ -113,7 +80,7 @@ do
 end
 
 var opts = new OptionContext
-var mode = new OptionEnum(["rope", "flatstr", "flatbuf"], "Mode", -1, "-m")
+var mode = new OptionEnum(["flatstr", "flatbuf"], "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")
@@ -132,15 +99,6 @@ var iterval = access_mode.value
 
 if modval == 0 then
        if iterval == 0 then
-               bench_rope_iter(nb_ccts.value, loops.value, strlen.value)
-       else if iterval == 1 then
-               bench_rope_index(nb_ccts.value, 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)
@@ -148,7 +106,7 @@ else if modval == 1 then
                opts.usage
                exit(-1)
        end
-else if modval == 2 then
+else if modval == 1 then
        if iterval == 0 then
                bench_flatbuf_iter(nb_ccts.value, loops.value, strlen.value)
        else if iterval == 1 then
index 5021e66..effb9ec 100644 (file)
@@ -13,18 +13,6 @@ module substr_bench
 
 import opts
 
-fun bench_rope(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
-       while cnt != loops do
-               x.substring(0,5)
-               cnt += 1
-       end
-end
-
 fun bench_flatstr(nb_cct: Int, loops: Int, strlen: Int)
 do
        var a = "a" * strlen
@@ -50,7 +38,7 @@ do
 end
 
 var opts = new OptionContext
-var mode = new OptionEnum(["rope", "flatstr", "flatbuf"], "Mode", -1, "-m")
+var mode = new OptionEnum(["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 loops = new OptionInt("Number of loops to be done", -1, "--loops")
 var strlen = new OptionInt("Length of the base string", -1, "--strlen")
@@ -66,10 +54,8 @@ end
 var modval = mode.value
 
 if modval == 0 then
-       bench_rope(nb_ccts.value, loops.value, strlen.value)
-else if modval == 1 then
        bench_flatstr(nb_ccts.value, loops.value, strlen.value)
-else if modval == 2 then
+else if modval == 1 then
        bench_flatbuf(nb_ccts.value, loops.value, strlen.value)
 else
        opts.usage