summaryrefslogtreecommitdiff
path: root/etc/compare-token-variants.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2009-10-19 17:31:55 +0000
committermurphy <murphy@rubychan.de>2009-10-19 17:31:55 +0000
commiteada01e24c1402c6e390579d60ca174f15e74f6b (patch)
tree4afc80632fc586f75122e0c6d0c469f762982011 /etc/compare-token-variants.rb
parentb8d26a6c7adbaaf49f595a5a721eec359aa7f2dc (diff)
downloadcoderay-eada01e24c1402c6e390579d60ca174f15e74f6b.tar.gz
etc. Dont mind it.
Diffstat (limited to 'etc/compare-token-variants.rb')
-rw-r--r--etc/compare-token-variants.rb33
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