提交 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) ...@@ -20,13 +20,14 @@ def initialize(script_path)
def benchmark(n) def benchmark(n)
@quiet = true @quiet = true
print ' ' print ' '
result = Benchmark.realtime do result = Benchmark.realtime do
n.times do |i| n.times do |i|
run run
reset!
print_progress(i) print_progress(i)
end end
end end
puts puts
result result
ensure ensure
...@@ -40,7 +41,8 @@ def say(message) ...@@ -40,7 +41,8 @@ def say(message)
private private
def define_run_method(script_path) def define_run_method(script_path)
script = File.read(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 end
def print_progress(i) def print_progress(i)
...@@ -94,10 +96,7 @@ def benchmark(sandbox) ...@@ -94,10 +96,7 @@ def benchmark(sandbox)
end end
def warmup(sandbox) def warmup(sandbox)
Benchmark.realtime do Benchmark.realtime { sandbox.run }
sandbox.run
sandbox.reset!
end
end end
def default_options def default_options
...@@ -109,7 +108,7 @@ def parse_options(args) ...@@ -109,7 +108,7 @@ def parse_options(args)
OptionParser.new do |opt| OptionParser.new do |opt|
opt.banner = "USAGE: #{$0} [options] [session script path]" 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('-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('--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 } 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.
先完成此消息的编辑!
想要评论请 注册