提交 ca812785 编写于 作者: J Jeremy Kemper

Fold reset! into the run method directly. Make -n options compatible with Ruby...

Fold reset! into the run method directly. Make -n options compatible with Ruby 1.9 whose option parser seems to call the block with nil value even when the option is omitted.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8477 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 c9d313dc
......@@ -20,13 +20,14 @@ def initialize(script_path)
def benchmark(n)
@quiet = true
print ' '
result = Benchmark.realtime do
n.times do |i|
run
reset!
print_progress(i)
end
end
puts
result
ensure
......@@ -40,7 +41,8 @@ def say(message)
private
def define_run_method(script_path)
script = File.read(script_path)
instance_eval "def run; #{script}; end", script_path, 1
source = "def run\n#{script}\nreset!\nend"
instance_eval source, script_path, 1
end
def print_progress(i)
......@@ -94,10 +96,7 @@ def benchmark(sandbox)
end
def warmup(sandbox)
Benchmark.realtime do
sandbox.run
sandbox.reset!
end
Benchmark.realtime { sandbox.run }
end
def default_options
......@@ -109,7 +108,7 @@ def parse_options(args)
OptionParser.new do |opt|
opt.banner = "USAGE: #{$0} [options] [session script path]"
opt.on('-n', '--times [0000]', 'How many requests to process. Defaults to 100.') { |v| options[:n] = v.to_i }
opt.on('-n', '--times [100]', 'How many requests to process. Defaults to 100.') { |v| options[:n] = v.to_i if v }
opt.on('-b', '--benchmark', 'Benchmark instead of profiling') { |v| options[:benchmark] = v }
opt.on('--open [CMD]', 'Command to open profile results. Defaults to "open %s &"') { |v| options[:open] = v }
opt.on('-h', '--help', 'Show this help') { puts opt; exit }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册