blob: a4edd839307ab49fd073d8707c4eb86dbf8feaf4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
|