bench/strings: Added bench for UTF-8 strings without index
authorLucas Bajolet <r4pass@hotmail.com>
Mon, 18 Aug 2014 17:22:07 +0000 (13:22 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Thu, 21 Aug 2014 17:30:19 +0000 (13:30 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

benchmarks/bench_strings.sh
benchmarks/strings/utf_chain_concat.nit [new file with mode: 0644]
benchmarks/strings/utf_iteration_bench.nit [new file with mode: 0644]
benchmarks/strings/utf_substr_bench.nit [new file with mode: 0644]

index 811eddd..54191a4 100755 (executable)
@@ -84,6 +84,17 @@ function bench_concat()
                bench_command $i flatbuffer$i ./chain_concat -m flatbuf --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
        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
+
        plot concat.gnu
 }
 
@@ -159,6 +170,28 @@ function bench_iteration()
                bench_command $i flatbuf_index$i ./iteration_bench -m flatbuf --iter-mode index --loops $2 --strlen $3 --ccts $i "NIT_GC_CHOOSER=large"
        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
+
        plot iter.gnu
 }
 
@@ -201,6 +234,17 @@ function bench_substr()
                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"
+       done
+
        plot substr.gnu
 }
 
@@ -224,8 +268,11 @@ if $verbose; then
 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 $@ ;;
diff --git a/benchmarks/strings/utf_chain_concat.nit b/benchmarks/strings/utf_chain_concat.nit
new file mode 100644 (file)
index 0000000..d720403
--- /dev/null
@@ -0,0 +1,42 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# This file is free software, which comes along with NIT.  This software is
+# distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+# without  even  the implied warranty of  MERCHANTABILITY or  FITNESS FOR A
+# PARTICULAR PURPOSE.  You can modify it is you want,  provided this header
+# is kept unaltered, and a notification of the changes is added.
+# You  are  allowed  to  redistribute it and sell it, alone or is a part of
+# another product.
+
+# Benches measuring the performance of several concatenations on Text variants
+module utf_chain_concat
+
+import opts
+import string_experimentations::utf8_noindex
+
+fun bench_flatstr(str_size: Int, nb_ccts: Int, loops: Int)
+do
+       var lft = "a" * str_size
+
+       for i in [0..loops] do
+               var str: String = lft
+               for j in [0..nb_ccts] do
+                       str += lft
+               end
+       end
+end
+
+var opts = new OptionContext
+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")
+opts.add_option(nb_ccts, loops, strlen)
+
+opts.parse(args)
+
+if nb_ccts.value == -1 or loops.value == -1 or strlen.value == -1 then
+       opts.usage
+       exit -1
+end
+
+bench_flatstr(strlen.value, nb_ccts.value, loops.value)
diff --git a/benchmarks/strings/utf_iteration_bench.nit b/benchmarks/strings/utf_iteration_bench.nit
new file mode 100644 (file)
index 0000000..80277c0
--- /dev/null
@@ -0,0 +1,74 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# This file is free software, which comes along with NIT.  This software is
+# distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+# without  even  the implied warranty of  MERCHANTABILITY or  FITNESS FOR A
+# PARTICULAR PURPOSE.  You can modify it is you want,  provided this header
+# is kept unaltered, and a notification of the changes is added.
+# You  are  allowed  to  redistribute it and sell it, alone or is a part of
+# another product.
+
+# Benches for iteration on variants of Text
+module utf_iteration_bench
+
+import opts
+import string_experimentations::utf8_noindex
+
+fun bench_flatstr_iter(nb_cct: Int, loops: Int, strlen: Int)
+do
+       var a = "a" * strlen
+       var x = a.as(FlatString)
+       for i in [0 .. nb_cct] do x = (x + a).as(FlatString)
+       var cnt = 0
+       var c: UnicodeChar
+       while cnt != loops do
+               var it = new FlatStringIter(x)
+               for i in it do
+                       c = i
+               end
+               cnt += 1
+       end
+end
+
+fun bench_flatstr_index(nb_cct: Int, loops: Int, strlen: Int)
+do
+       var a = "a" * strlen
+       var x = a.as(FlatString)
+       for i in [0 .. nb_cct] do x = (x + a).as(FlatString)
+       var cnt = 0
+       var c: UnicodeChar
+       var pos = 0
+       while cnt != loops do
+               pos = 0
+               while pos < x.length do
+                       c = x.char_at(pos)
+                       pos += 1
+               end
+               cnt += 1
+       end
+end
+
+var opts = new OptionContext
+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(nb_ccts, loops, strlen, access_mode)
+
+opts.parse(args)
+
+if nb_ccts.value == -1 or loops.value == -1 or strlen.value == -1 then
+       opts.usage
+       exit(-1)
+end
+
+var iterval = access_mode.value
+
+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
diff --git a/benchmarks/strings/utf_substr_bench.nit b/benchmarks/strings/utf_substr_bench.nit
new file mode 100644 (file)
index 0000000..7d71a8b
--- /dev/null
@@ -0,0 +1,42 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# This file is free software, which comes along with NIT.  This software is
+# distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+# without  even  the implied warranty of  MERCHANTABILITY or  FITNESS FOR A
+# PARTICULAR PURPOSE.  You can modify it is you want,  provided this header
+# is kept unaltered, and a notification of the changes is added.
+# You  are  allowed  to  redistribute it and sell it, alone or is a part of
+# another product.
+
+# Benches on the substring operation on variants of Text
+module utf_substr_bench
+
+import opts
+import string_experimentations::utf8_noindex
+
+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
+       var cnt = 0
+       while cnt != loops do
+               x.substring(0,5)
+               cnt += 1
+       end
+end
+
+var opts = new OptionContext
+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(nb_ccts, loops, strlen)
+
+opts.parse(args)
+
+if nb_ccts.value == -1 or loops.value == -1 or strlen.value == -1 then
+       opts.usage
+       exit(-1)
+end
+
+bench_flatstr(nb_ccts.value, loops.value, strlen.value)