aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-08-09 03:50:34 -0300
committerYehuda Katz <wycats@gmail.com>2009-08-09 04:12:09 -0300
commit0d539947017e0ba04601889e2a3e01a64bcadf69 (patch)
treebf9ac2b52503ed123e04c71885d640a05a838969
parente8849203dc68d1a2fabf5e6b51b379ad1c51f8c8 (diff)
downloadrails-0d539947017e0ba04601889e2a3e01a64bcadf69.tar.gz
rails-0d539947017e0ba04601889e2a3e01a64bcadf69.tar.bz2
rails-0d539947017e0ba04601889e2a3e01a64bcadf69.zip
Make bench harness produce output that is easier to compare
-rw-r--r--actionpack/examples/minimal.rb32
1 files changed, 21 insertions, 11 deletions
diff --git a/actionpack/examples/minimal.rb b/actionpack/examples/minimal.rb
index 2697d1f391..a9015da053 100644
--- a/actionpack/examples/minimal.rb
+++ b/actionpack/examples/minimal.rb
@@ -10,8 +10,12 @@ require 'action_view'
require 'benchmark'
class Runner
- def initialize(app)
- @app = app
+ def initialize(app, output)
+ @app, @output = app, output
+ end
+
+ def puts(*)
+ super if @output
end
def call(env)
@@ -20,16 +24,22 @@ class Runner
end
def report(env, response)
+ return unless ENV["DEBUG"]
out = env['rack.errors']
out.puts response[0], response[1].to_yaml, '---'
response[2].each { |part| out.puts part }
out.puts '---'
end
- def self.run(app, n, label = nil)
- puts '=' * label.size, label, '=' * label.size if label
+ def self.puts(*)
+ super if @output
+ end
+
+ def self.run(app, n, label, output = true)
+ @output = output
+ puts label, '=' * label.size if label
env = Rack::MockRequest.env_for("/").merge('n' => n, 'rack.input' => StringIO.new(''), 'rack.errors' => $stdout)
- t = Benchmark.realtime { new(app).call(env) }
+ t = Benchmark.realtime { new(app, output).call(env) }
puts "%d ms / %d req = %.1f usec/req" % [10**3 * t, n, 10**6 * t / n]
puts
end
@@ -82,12 +92,12 @@ class HttpPostController < ActionController::Metal
end
unless ENV["PROFILE"]
- Runner.run(BasePostController.action(:overhead), N, 'overhead')
- Runner.run(BasePostController.action(:index), N, 'index')
- Runner.run(BasePostController.action(:partial), N, 'partial')
- Runner.run(BasePostController.action(:many_partials), N, 'many_partials')
- Runner.run(BasePostController.action(:partial_collection), N, 'collection')
- Runner.run(BasePostController.action(:show_template), N, 'template')
+ Runner.run(BasePostController.action(:overhead), N, 'overhead', false)
+ Runner.run(BasePostController.action(:index), N, 'index', false)
+ Runner.run(BasePostController.action(:partial), N, 'partial', false)
+ Runner.run(BasePostController.action(:many_partials), N, 'many_partials', false)
+ Runner.run(BasePostController.action(:partial_collection), N, 'collection', false)
+ Runner.run(BasePostController.action(:show_template), N, 'template', false)
(ENV["M"] || 1).to_i.times do
Runner.run(BasePostController.action(:overhead), N, 'overhead')