1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/lib/rails/commands/benchmarker.rb
2012-01-13 00:41:12 +05:30

34 lines
1 KiB
Ruby

require 'optparse'
require 'rails/test_help'
require 'rails/performance_test_help'
ARGV.push('--benchmark') # HAX
require 'active_support/testing/performance'
ARGV.pop
def options
options = {}
defaults = ActiveSupport::Testing::Performance::DEFAULTS
OptionParser.new do |opt|
opt.banner = "Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS]"
opt.on('-r', '--runs N', Numeric, 'Number of runs.', "Default: #{defaults[:runs]}") { |r| options[:runs] = r }
opt.on('-o', '--output PATH', String, 'Directory to use when writing the results.', "Default: #{defaults[:output]}") { |o| options[:output] = o }
opt.on('-m', '--metrics a,b,c', Array, 'Metrics to use.', "Default: #{defaults[:metrics].join(",")}") { |m| options[:metrics] = m.map(&:to_sym) }
opt.parse!(ARGV)
end
options
end
class BenchmarkerTest < ActionDispatch::PerformanceTest #:nodoc:
self.profile_options = options
ARGV.each do |expression|
eval <<-RUBY
def test_#{expression.parameterize('_')}
#{expression}
end
RUBY
end
end