2005-04-14 04:23:50 -04:00
|
|
|
if ARGV.empty?
|
2010-02-02 19:16:26 -05:00
|
|
|
puts "Usage: benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ..."
|
2005-10-14 10:46:27 -04:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
N = Integer(ARGV.first)
|
|
|
|
ARGV.shift
|
|
|
|
rescue ArgumentError
|
|
|
|
N = 1
|
2005-04-14 04:23:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
require 'benchmark'
|
|
|
|
include Benchmark
|
|
|
|
|
2005-04-18 15:03:25 -04:00
|
|
|
# Don't include compilation in the benchmark
|
2005-10-14 10:46:27 -04:00
|
|
|
ARGV.each { |expression| eval(expression) }
|
2005-04-18 15:03:25 -04:00
|
|
|
|
2005-04-14 04:23:50 -04:00
|
|
|
bm(6) do |x|
|
2005-10-14 10:46:27 -04:00
|
|
|
ARGV.each_with_index do |expression, idx|
|
|
|
|
x.report("##{idx + 1}") { N.times { eval(expression) } }
|
2005-04-14 04:23:50 -04:00
|
|
|
end
|
2009-10-16 20:28:56 -04:00
|
|
|
end
|