-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
39 lines (32 loc) · 874 Bytes
/
run
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
34
35
36
37
38
39
#!/usr/bin/env ruby
require 'benchmark'
require 'strscan'
MY_DIR = File.dirname(__FILE__)
$LOAD_PATH.unshift MY_DIR
require 'bench'
times = (ARGV.join(' ')[/--times (\d+)/, 1] || 1).to_i
repeat = (ARGV.join(' ')[/--repeat (\d+)/, 1] || 1).to_i
if defined? RUBY_DESCRIPTION
puts RUBY_DESCRIPTION
else
puts "#{RUBY_ENGINE rescue 'ruby'} #{RUBY_VERSION} #{RUBY_RELEASE_DATE}"
end
Benchmark.bm 30 do |bm|
Dir.chdir MY_DIR do
for benchmark in Dir["strscan/**/bm_#{ARGV.grep(/^[a-z]/).first || '*'}.rb"].sort
load benchmark
bench = Bench.last_instance
name = File.basename(benchmark)[/\Abm_(.*?)\.rb/, 1]
repeat.times do |i|
bench.before
bm.report name + ":#{i + 1 if repeat > 1}" do
times.times do
bench.run
end
end
bench.after
end
puts
end
end
end