From 86455d31f2ee88c9f476627ee6ebf1b242d962bb Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 14 Oct 2005 14:46:27 +0000 Subject: Sanitize benchmarker. [times] argument is optional, defaults to 1. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2583 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/lib/commands/perform/benchmarker.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/commands/perform/benchmarker.rb b/railties/lib/commands/perform/benchmarker.rb index 296192f53c..b12cf57215 100644 --- a/railties/lib/commands/perform/benchmarker.rb +++ b/railties/lib/commands/perform/benchmarker.rb @@ -2,7 +2,14 @@ if ARGV.empty? puts "Usage: ./script/perform benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ..." - exit + exit 1 +end + +begin + N = Integer(ARGV.first) + ARGV.shift +rescue ArgumentError + N = 1 end require RAILS_ROOT + '/config/environment' @@ -10,10 +17,10 @@ require 'benchmark' include Benchmark # Don't include compilation in the benchmark -ARGV[1..-1].each { |expression| eval(expression) } +ARGV.each { |expression| eval(expression) } bm(6) do |x| - ARGV[1..-1].each_with_index do |expression, idx| - x.report("##{idx + 1}") { ARGV[0].to_i.times { eval(expression) } } + ARGV.each_with_index do |expression, idx| + x.report("##{idx + 1}") { N.times { eval(expression) } } end -end \ No newline at end of file +end -- cgit v1.2.3