benchmarks/string: Updated bench scripts for strings
[nit.git] / benchmarks / strings / bench_strings.sh
similarity index 53%
rename from benchmarks/bench_strings.sh
rename to benchmarks/strings/bench_strings.sh
index 16992e9..a710dc0 100755 (executable)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-source ./bench_common.sh
-source ./bench_plot.sh
+source ../bench_common.sh
+source ../bench_plot.sh
 
 # Default number of times a command must be run with bench_command
 # Can be overrided with 'the option -n'
-count=2
+count=5
 
 function usage()
 {
@@ -28,8 +28,6 @@ function usage()
        echo "  -h: this help"
        echo ""
        echo "Benches : "
-       echo "  all : all benches"
-       echo "    - usage : * max_nb_cct loops strlen"
        echo "  iter: bench iterations"
        echo "    - usage : iter max_nb_cct loops strlen"
        echo "  cct: concatenation benching"
@@ -40,21 +38,20 @@ function usage()
        echo "    - usage : array nb_cct loops max_arrlen"
 }
 
-function benches()
-{
-       bench_concat $@;
-       bench_iteration $@;
-       bench_substr $@;
-       bench_array $@;
-}
-
 function bench_array()
 {
+       if [ -d arraytos ]; then
+               rm arraytos/*
+       else
+               mkdir arraytos
+       fi
+       cd arraytos
+
        if $verbose; then
                echo "*** Benching Array.to_s performance ***"
        fi
 
-       ../bin/nitc --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\""
+       ../../../bin/nitc --global ../array_tos.nit -m ../array_to_s_vars/array_to_s_rope.nit
 
        prepare_res arr_tos_ropes.out arr_tos_ropes ropes
        if $verbose; then
@@ -64,23 +61,10 @@ function bench_array()
                if $verbose; then
                        echo "String length = $i, Concats/loop = $1, Loops = $2"
                fi
-               bench_command $i ropes$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
+               bench_command $i ropes$i ./array_tos --loops $2 --strlen $i --ccts $1
        done
 
-       ../bin/nitc --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/nitc --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_flatstr.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+       ../../../bin/nitc --global ../array_tos.nit -m ../array_to_s_vars/array_to_s_flatstr.nit
 
        prepare_res arr_tos_flat.out arr_tos_flat flatstring
        if $verbose; then
@@ -90,10 +74,10 @@ function bench_array()
                if $verbose; then
                        echo "String length = $i, Concats/loop = $1, Loops = $2"
                fi
-               bench_command $i flatstring$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
+               bench_command $i flatstring$i ./array_tos --loops $2 --strlen $i --ccts $1
        done
 
-       ../bin/nitc --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_buffer.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+       ../../../bin/nitc --global ../array_tos.nit -m ../array_to_s_vars/array_to_s_buffer.nit
 
        prepare_res arr_tos_buf.out arr_tos_buf flatbuffer
        if $verbose; then
@@ -103,10 +87,10 @@ function bench_array()
                if $verbose; then
                        echo "String length = $i, Concats/loop = $1, Loops = $2"
                fi
-               bench_command $i flatbuffer$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
+               bench_command $i flatbuffer$i ./array_tos --loops $2 --strlen $i --ccts $1
        done
 
-       ../bin/nitc --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_manual.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+       ../../../bin/nitc --global ../array_tos.nit -m ../array_to_s_vars/array_to_s_manual.nit
 
        prepare_res arr_tos_man.out arr_tos_man memmove
        if $verbose; then
@@ -116,10 +100,10 @@ function bench_array()
                if $verbose; then
                        echo "String length = $i, Concats/loop = $1, Loops = $2"
                fi
-               bench_command $i memmove$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
+               bench_command $i memmove$i ./array_tos --loops $2 --strlen $i --ccts $1
        done
 
-       ../bin/nitc --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_man_buf.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+       ../../../bin/nitc --global ../array_tos.nit -m ../array_to_s_vars/array_to_s_man_buf.nit
 
        prepare_res arr_tos_man_buf.out arr_tos_man_buf flatbuf_with_capacity
        if $verbose; then
@@ -129,10 +113,10 @@ function bench_array()
                if $verbose; then
                        echo "String length = $i, Concats/loop = $1, Loops = $2"
                fi
-               bench_command $i flatbuf_with_capacity$i ./array_tos --loops $2 --strlen $i --ccts $1 "NIT_GC_CHOOSER=large"
+               bench_command $i flatbuf_with_capacity$i ./array_tos --loops $2 --strlen $i --ccts $1
        done
 
-       ../bin/nitc --global ./strings/array_tos.nit -m ./strings/array_to_s_vars/array_to_s_rope_buf.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+       ../../../bin/nitc --global ../array_tos.nit -m ../array_to_s_vars/array_to_s_rope_buf.nit
 
        prepare_res arr_tos_rope_buf.out arr_tos_rope_buf ropebuf
        if $verbose; then
@@ -142,16 +126,24 @@ function bench_array()
                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"
+               bench_command $i ropebuf$i ./array_tos --loops $2 --strlen $i --ccts $1
        done
 
        plot array_tos.gnu
+
+       cd ..
 }
 
 function bench_concat()
 {
-       ../bin/nitc --global ./strings/chain_concat.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
-       ../bin/nitc --global ./strings/utf_chain_concat.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+       if [ -d string_concat ]; then
+               rm string_concat/*
+       else
+               mkdir string_concat
+       fi
+       cd string_concat
+
+       ../../../bin/nitc --global ../chain_concat.nit
 
        if $verbose; then
                echo "*** Benching concat performance ***"
@@ -165,7 +157,7 @@ function bench_concat()
                if $verbose; then
                        echo "String length = $i, Concats/loop = $2, Loops = $3"
                fi
-               bench_command $i flatstring$i ./chain_concat -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i flatstring$i ./chain_concat -m flatstr --loops $2 --strlen $3 --ccts $i
        done
 
        prepare_res concat_buf.out concat_buf flatbuffer
@@ -176,22 +168,9 @@ function bench_concat()
                if $verbose; then
                        echo "String length = $i, Concats/loop = $2, Loops = $3"
                fi
-               bench_command $i flatbuffer$i ./chain_concat -m flatbuf --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i flatbuffer$i ./chain_concat -m flatbuf --loops $2 --strlen $3 --ccts $i
        done
 
-       prepare_res concat_flatstr_utf8_noindex.out concat_flatstr_utf8_noindex flatstring_utf8_noindex
-       if $verbose; then
-               echo "FlatString UTF-8 (without index) :"
-       fi
-       for i in `seq 1 "$1"`; do
-               if $verbose; then
-                       echo "String length = $i, Concats/loop = $2, Loops = $3"
-               fi
-               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
-
-       ../bin/nitc --global ./strings/chain_concat.nit -m ../lib/standard/ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
-
        prepare_res concat_ropes.out concat_ropes ropes
        if $verbose; then
                echo "Ropes :"
@@ -200,46 +179,39 @@ function bench_concat()
                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"
+               bench_command $i ropes$i ./chain_concat -m ropestr --loops $2 --strlen $3 --ccts $i
        done
 
-       ../bin/nitc --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 "buffered 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 buf_ropes$i ./chain_concat -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
-       done
-
-       ../bin/nitc --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 "buffered ropes :"
+               echo "Rope Buffer:"
        fi
        for i in `seq 1 "$1"`; do
                if $verbose; then
                        echo "string length = $i, concats/loop = $2, loops = $3"
                fi
-               bench_command $i cctbuf_ropes$i ./chain_cct_ropebuf --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i buf_ropes$i ./chain_concat -m ropebuf --loops $2 --strlen $3 --ccts $i
        done
 
        plot concat.gnu
+
+       cd ..
 }
 
 function bench_iteration()
 {
+       if [ -d string_iter ]; then
+               rm string_iter/*
+       else
+               mkdir string_iter
+       fi
+       cd string_iter
+
        if $verbose; then
                echo "*** Benching iteration performance ***"
        fi
 
-       ../bin/nitc --global ./strings/iteration_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
-       ../bin/nitc --global ./strings/utf_iteration_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+       ../../../bin/nitc --global ../iteration_bench.nit
 
        prepare_res iter_flat_iter.out iter_flat_iter flatstring_iter
        if $verbose; then
@@ -249,7 +221,7 @@ function bench_iteration()
                if $verbose; then
                        echo "String base length = $1, Concats = $i, Loops = $3"
                fi
-               bench_command $i flatstr_iter$i ./iteration_bench -m flatstr --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i flatstr_iter$i ./iteration_bench -m flatstr --iter-mode iterator --loops $2 --strlen $3 --ccts $i
        done
 
        prepare_res iter_flat_index.out iter_flat_index flatstring_index
@@ -260,7 +232,7 @@ function bench_iteration()
                if $verbose; then
                        echo "String base length = $1, Concats = $i, Loops = $3"
                fi
-               bench_command $i flatstr_index$i ./iteration_bench -m flatstr --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i flatstr_index$i ./iteration_bench -m flatstr --iter-mode index --loops $2 --strlen $3 --ccts $i
        done
 
        prepare_res iter_buf_iter.out iter_buf_iter flatbuffer_iter
@@ -271,7 +243,7 @@ function bench_iteration()
                if $verbose; then
                        echo "String base length = $1, Concats = $i, Loops = $3"
                fi
-               bench_command $i flatbuf_iter$i ./iteration_bench -m flatbuf --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i flatbuf_iter$i ./iteration_bench -m flatbuf --iter-mode iterator --loops $2 --strlen $3 --ccts $i
        done
 
        prepare_res iter_buf_index.out iter_buf_index flatbuffer_index
@@ -282,33 +254,9 @@ function bench_iteration()
                if $verbose; then
                        echo "String base length = $1, Concats = $i, Loops = $3"
                fi
-               bench_command $i flatbuf_index$i ./iteration_bench -m flatbuf --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i flatbuf_index$i ./iteration_bench -m flatbuf --iter-mode index --loops $2 --strlen $3 --ccts $i
        done
 
-       prepare_res iter_flat_utf8_noindex_iter.out iter_flat_iter_utf8_noindex flatstring_utf8_noindex_iter
-       if $verbose; then
-               echo "FlatStrings by iterator :"
-       fi
-       for i in `seq 1 "$1"`; do
-               if $verbose; then
-                       echo "String base length = $1, Concats = $i, Loops = $3"
-               fi
-               bench_command $i flatstr_iter_utf8_noindex$i ./utf_iteration_bench -m flatstr_utf8_noindex --iter-mode iterator --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
-       done
-
-       prepare_res iter_flat_utf8_noindex_index.out iter_flat_index_utf8_noindex flatstring_utf8_noindex_index
-       if $verbose; then
-               echo "FlatStrings by index :"
-       fi
-       for i in `seq 1 "$1"`; do
-               if $verbose; then
-                       echo "String base length = $1, Concats = $i, Loops = $3"
-               fi
-               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
-
-       ../bin/nitc --global ./strings/iteration_bench.nit -m ../lib/standard/ropes.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
-
        prepare_res iter_ropes_iter.out iter_ropes_iter ropes_iter
        if $verbose; then
                echo "Ropes by iterator :"
@@ -317,7 +265,7 @@ function bench_iteration()
                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"
+               bench_command $i ropes_iter$i ./iteration_bench -m ropestr --iter-mode iterator --loops $2 --strlen $3 --ccts $i
        done
 
        prepare_res iter_ropes_index.out iter_ropes_index ropes_index
@@ -328,44 +276,50 @@ function bench_iteration()
                if $verbose; then
                        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"
+               bench_command $i ropes_index$i ./iteration_bench -m ropestr --iter-mode index --loops $2 --strlen $3 --ccts $i
        done
 
-       ../bin/nitc --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 :"
+               echo "RopeBuffer 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"
+               bench_command $i buf_ropes_iter$i ./iteration_bench -m ropebuf --iter-mode iterator --loops $2 --strlen $3 --ccts $i
        done
 
        prepare_res iter_buf_ropes_index.out iter_buf_ropes_index buf_ropes_index
        if $verbose; then
-               echo "Buffered Ropes by index :"
+               echo "RopeBuffer 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 buf_ropes_index$i ./iteration_bench -m flatstr --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i buf_ropes_index$i ./iteration_bench -m ropebuf --iter-mode index --loops $2 --strlen $3 --ccts $i
        done
 
        plot iter.gnu
+
+       cd ..
 }
 
 function bench_substr()
 {
+       if [ -d string_substr ]; then
+               rm string_substr/*
+       else
+               mkdir string_substr
+       fi
+       cd string_substr
+
        if $verbose; then
                echo "*** Benching substring performance ***"
        fi
 
-       ../bin/nitc --global ./strings/substr_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
-       ../bin/nitc --global ./strings/utf_substr_bench.nit --make-flags "CFLAGS=\"-g -O2 -DNOBOEHM\""
+       ../../../bin/nitc --global ../substr_bench.nit
 
        prepare_res substr_flat.out substr_flat flatstring
        if $verbose; then
@@ -375,7 +329,7 @@ function bench_substr()
                if $verbose; then
                        echo "String length = $i, loops = $2, Loops = $3"
                fi
-               bench_command $i flatstring$i ./substr_bench -m flatstr --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i flatstring$i ./substr_bench -m flatstr --loops $2 --strlen $3 --ccts $i
        done
 
        prepare_res substr_buf.out substr_buf flatbuffer
@@ -386,22 +340,9 @@ function bench_substr()
                if $verbose; then
                        echo "String length = $i, loops = $2, Loops = $3"
                fi
-               bench_command $i flatbuffer$i ./substr_bench -m flatbuf --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
-       done
-
-       prepare_res substr_flat_utf8_noindex.out substr_flat_utf8_noindex flatstring_utf8_noindex
-       if $verbose; then
-               echo "FlatStrings UTF-8 (without index) :"
-       fi
-       for i in `seq 1 "$1"`; do
-               if $verbose; then
-                       echo "String length = $i, loops = $2, Loops = $3"
-               fi
-               bench_command $i flatstring_utf8_noindex$i ./utf_substr_bench -m flatstr_utf8_noindex --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
+               bench_command $i flatbuffer$i ./substr_bench -m flatbuf --loops $2 --strlen $3 --ccts $i
        done
 
-       ../bin/nitc --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 :"
@@ -410,22 +351,23 @@ function bench_substr()
                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"
+               bench_command $i ropes$i ./substr_bench -m ropestr --loops $2 --strlen $3 --ccts $i
        done
 
-       ../bin/nitc --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 :"
+               echo "RopeBuffers :"
        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"
+               bench_command $i buf_ropes$i ./substr_bench -m ropebuf --loops $2 --strlen $3 --ccts $i
        done
+
        plot substr.gnu
+
+       cd ..
 }
 
 stop=false
@@ -448,6 +390,5 @@ case "$1" in
        cct) shift; bench_concat $@ ;;
        substr) shift; bench_substr $@ ;;
        array) shift; bench_array $@ ;;
-       all) shift; benches $@ ;;
        *) usage; exit;;
 esac