summaryrefslogtreecommitdiff
path: root/etc/compare-token-variants.rb
diff options
context:
space:
mode:
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