# To be used as a Mixin at compile-time for benchmarking purposes.
module array_to_s_buffer
+intrude import standard::collection::array
+import standard::string
+
redef class Array[E]
redef fun to_s: String do
var s = new FlatBuffer
# To be used as a Mixin at compile-time for benchmarking purposes.
module array_to_s_flatstr
+intrude import standard::string
+
+redef class FlatString
+ redef fun +(o) do
+ var mlen = length
+ var slen = o.length
+ var nns = new NativeString(mlen + slen)
+ items.copy_to(nns, mlen, index_from, 0)
+ if o isa FlatString then
+ o.items.copy_to(nns, slen, o.index_from, mlen)
+ else
+ var pos = mlen
+ for i in o.chars do
+ nns[pos] = i
+ pos += 1
+ end
+ end
+ return nns.to_s_with_length(mlen)
+ end
+end
+
redef class Array[E]
redef fun to_s do
# To be used as a Mixin at compile-time for benchmarking purposes.
module array_to_s_man_buf
-redef class NativeArray[E]
- new(length: Int) is intern
-end
+intrude import standard::collection::array
+import standard::string
redef class Array[E]
redef fun to_s: String do
# To be used as a Mixin at compile-time for benchmarking purposes.
module array_to_s_rope
+intrude import standard::collection::array
+intrude import standard::ropes
+
redef class Array[E]
redef fun to_s do
- var i = 1
var l = length
+ var it = _items
if l == 0 then return ""
- var s: String = new RopeString.from(self[0].to_s)
- var its = _items
- while i < l do
- var e = its[i]
- if e != null then s += e.to_s
- i += 1
+ if l == 1 then return it[0].to_s
+ var c = new Concat(it[0].to_s, it[1].to_s)
+ for i in [2 .. l[ do
+ c = new Concat(c, it[i].to_s)
end
- return s
+ return c
end
+
end
--- /dev/null
+# 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.
+
+# Implementation of Array::to_s with RopeBuffer exclusively
+#
+# To be used as a Mixin at compile-time for benchmarking purposes.
+module array_to_s_rope_buf
+
+intrude import standard::collection::array
+import standard::ropes
+
+redef class Array[E]
+ redef fun to_s: String do
+ var s = new RopeBuffer
+ var i = 0
+ var l = length
+ var its = _items
+ while i < l do
+ var e = its[i]
+ if e != null then s.append(e.to_s)
+ i += 1
+ end
+ return s.to_s
+ end
+end
# 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()
{
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"
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
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
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
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
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
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
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 ***"
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
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 :"
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
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
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
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
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 :"
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
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
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
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 :"
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
cct) shift; bench_concat $@ ;;
substr) shift; bench_substr $@ ;;
array) shift; bench_array $@ ;;
- all) shift; benches $@ ;;
*) usage; exit;;
esac
# Benches measuring the performance of several concatenations on Text variants
module chain_concat
+intrude import standard::ropes
import opts
+redef class FlatString
+ redef fun +(o) do
+ var mlen = length
+ var slen = o.length
+ var nlen = mlen + slen
+ var ns = new NativeString(nlen + 1)
+ items.copy_to(ns, mlen, index_from, 0)
+ if o isa FlatString then
+ o.items.copy_to(ns, slen, o.index_from, 0)
+ else
+ var pos = mlen
+ for i in o.chars do
+ ns[pos] = i
+ pos += 1
+ end
+ end
+ return ns.to_s_with_length(nlen)
+ end
+end
+
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
+ for i in [0 .. loops[ do
+ var str: String = ""
+ for j in [0 .. nb_ccts[ do
str += lft
end
end
end
+fun bench_ropestr(str_size, nb_ccts, loops: Int) do
+ var lft = "a" * str_size
+
+ for i in [0 .. loops[ do
+ var str: String = ""
+ for j in [0 .. nb_ccts[ do
+ str = new Concat(str, lft)
+ end
+ end
+end
+
fun bench_flatbuf(str_size: Int, nb_ccts: Int, loops: Int)
do
var lft = "a" * str_size
- for i in [0..loops] do
- var buf = new FlatBuffer.from(lft)
- for j in [0..nb_ccts] do
+ for i in [0 .. loops[ do
+ var buf = new FlatBuffer
+ for j in [0 .. nb_ccts[ do
+ buf.append(lft)
+ end
+ end
+end
+
+fun bench_ropebuf(str_size: Int, nb_ccts: Int, loops: Int)
+do
+ var lft = "a" * str_size
+
+ for i in [0 .. loops[ do
+ var buf = new RopeBuffer
+ for j in [0 .. nb_ccts[ do
buf.append(lft)
end
- buf.to_s
end
end
var opts = new OptionContext
-var mode = new OptionEnum(["flatstr", "flatbuf"], "Mode", -1, "-m")
+var mode = new OptionEnum(["flatstr", "ropestr", "flatbuf", "ropebuf"], "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")
if modval == 0 then
bench_flatstr(strlen.value, nb_ccts.value, loops.value)
else if modval == 1 then
+ bench_ropestr(strlen.value, nb_ccts.value, loops.value)
+else if modval == 2 then
bench_flatbuf(strlen.value, nb_ccts.value, loops.value)
+else if modval == 3 then
+ bench_ropebuf(strlen.value, nb_ccts.value, loops.value)
+
else
opts.usage
exit -1
module iteration_bench
import opts
+intrude import standard::ropes
+
+redef class Concat
+ redef fun +(o) do
+ var s = o.to_s
+ return new Concat(self, s)
+ end
+end
+
+redef class FlatString
+ redef fun +(o) do
+ var s = o.to_s
+ var b = new FlatBuffer.with_capacity(length + s.length)
+ b.append self
+ for i in s.substrings do b.append i
+ return b.to_s
+ 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
+ a = a * nb_cct
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
fun bench_flatstr_index(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 cnt = 0
+ var c: Char
+ var pos = 0
+ while cnt != loops do
+ pos = 0
+ while pos < a.length do
+ c = a[pos]
+ pos += 1
+ end
+ cnt += 1
+ end
+end
+
+fun bench_ropestr_iter(nb_cct: Int, loops: Int, strlen: Int)
+do
+ var a = "a" * strlen
+ var x: String = new Concat(a, a)
+ for i in [2 .. nb_cct[ do x = new Concat(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_ropestr_index(nb_cct: Int, loops: Int, strlen: Int)
+do
+ var a = "a" * strlen
+ var x: String = new Concat(a, a)
+ for i in [2 .. nb_cct[ do x = new Concat(x, a)
var cnt = 0
var c: Char
var pos = 0
fun bench_flatbuf_iter(nb_cct: Int, loops: Int, strlen: Int)
do
var a = "a" * strlen
+ a = a * nb_cct
var x = new FlatBuffer.from(a)
- for i in [0 .. nb_cct] do x.append a
var cnt = 0
var c: Char
while cnt != loops do
fun bench_flatbuf_index(nb_cct: Int, loops: Int, strlen: Int)
do
var a = "a" * strlen
+ a = a * nb_cct
var x = new FlatBuffer.from(a)
- for i in [0 .. nb_cct] do x.append 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_ropebuf_iter(nb_cct: Int, loops: Int, strlen: Int)
+do
+ var a = "a" * strlen
+ var x = new RopeBuffer.from(a)
+ for i in [0 .. nb_cct[ do x.append 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_ropebuf_index(nb_cct: Int, loops: Int, strlen: Int)
+do
+ var a = "a" * strlen
+ var x = new RopeBuffer.from(a)
+ for i in [0 .. nb_cct[ do x.append a
var cnt = 0
var c: Char
var pos = 0
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 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")
opts.usage
exit(-1)
end
+else if modval == 2 then
+ if iterval == 0 then
+ bench_ropestr_iter(nb_ccts.value, loops.value, strlen.value)
+ else if iterval == 1 then
+ bench_ropestr_index(nb_ccts.value, loops.value, strlen.value)
+ else
+ opts.usage
+ exit(-1)
+ end
+else if modval == 3 then
+ if iterval == 0 then
+ bench_ropebuf_iter(nb_ccts.value, loops.value, strlen.value)
+ else if iterval == 1 then
+ bench_ropebuf_index(nb_ccts.value, loops.value, strlen.value)
+ else
+ opts.usage
+ exit(-1)
+ end
else
opts.usage
exit(-1)
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
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")
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)
+++ /dev/null
-# 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)
+++ /dev/null
-# 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
+++ /dev/null
-# 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)