Permalink
Browse files

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
  • Loading branch information...
jeremy committed Oct 14, 2005
1 parent d8738be commit 86455d31f2ee88c9f476627ee6ebf1b242d962bb
Showing with 12 additions and 5 deletions.
  1. +12 −5 railties/lib/commands/perform/benchmarker.rb
@@ -2,18 +2,25 @@
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'
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
+end

0 comments on commit 86455d3

Please sign in to comment.