diff options
author | murphy <murphy@rubychan.de> | 2009-10-19 17:31:55 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2009-10-19 17:31:55 +0000 |
commit | eada01e24c1402c6e390579d60ca174f15e74f6b (patch) | |
tree | 4afc80632fc586f75122e0c6d0c469f762982011 /etc/compare-token-variants.rb | |
parent | b8d26a6c7adbaaf49f595a5a721eec359aa7f2dc (diff) | |
download | coderay-eada01e24c1402c6e390579d60ca174f15e74f6b.tar.gz |
etc. Dont mind it.
Diffstat (limited to 'etc/compare-token-variants.rb')
-rw-r--r-- | etc/compare-token-variants.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/etc/compare-token-variants.rb b/etc/compare-token-variants.rb new file mode 100644 index 0000000..a4edd83 --- /dev/null +++ b/etc/compare-token-variants.rb @@ -0,0 +1,33 @@ +require "benchmark" +require "strscan" + +TESTS = 2_000_000 +S = 'begin ' * TESTS +r = /begin / + +len = nil +Benchmark.bm 20 do |results| + results.report 'string' do + s = StringScanner.new S + a = [] + while matched = s.scan(r) + a << [matched, :test] + end + end + results.report 'length' do + s = StringScanner.new S + a = [] + while len = s.skip(r) + a << [len, :test] + end + end + results.report 'two arrays' do + s = StringScanner.new S + a = [] + b = [] + while matched = s.scan(r) + a << len + b << :test + end + end +end
\ No newline at end of file |