2005-04-14 04:23:50 -04:00
|
|
|
if ARGV.empty?
|
2005-12-12 21:32:05 -05:00
|
|
|
puts "Usage: ./script/performance/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
|
|
|
|
|
2005-10-13 23:22:18 -04:00
|
|
|
require RAILS_ROOT + '/config/environment'
|
2005-04-14 04:23:50 -04:00
|
|
|
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
|
2005-10-14 10:46:27 -04:00
|
|
|
end
|