Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update bench harness in 2.3 to match master output

  • Loading branch information...
commit ee8fe3ae4e7c3eed99c77ccb3872c972c12a4102 1 parent 3cad1df
@wycats wycats authored
Showing with 38 additions and 19 deletions.
  1. +38 −19 actionpack/examples/minimal.rb
View
57 actionpack/examples/minimal.rb
@@ -3,8 +3,12 @@
require "action_controller"
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)
@@ -13,17 +17,24 @@ def call(env)
end
def report(env, response)
- out = env['rack.errors']
- p response.headers
- out.puts response.status, response.headers.to_yaml, '---'
- response.body.each { |part| out.puts part }
- out.puts '---'
+ if ENV["DEBUG"]
+ out = env['rack.errors']
+ p response.headers
+ out.puts response.status, response.headers.to_yaml, '---'
+ response.body.each { |part| out.puts part }
+ out.puts '---'
+ end
+ end
+
+ def self.puts(*)
+ super if @output
end
- def self.run(app, n, label = nil, uri = "/")
- puts '=' * label.size, label, '=' * label.size if label
+ def self.run(app, n, label = nil, uri = "/", output = true)
+ @output = output
+ puts label, '=' * label.size if label
env = Rack::MockRequest.env_for(uri).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
@@ -57,12 +68,20 @@ def show_template
# p BasePostController.call(Rack::MockRequest.env_for("/?action=index").merge("REQUEST_URI" => "/")).body
-Runner.run(BasePostController, N, 'index', "/?action=index")
-Runner.run(BasePostController, N, 'partial', "/?action=partial")
-Runner.run(BasePostController, N, 'many partials', "/?action=many_partials")
-Runner.run(BasePostController, N, 'collection', "/?action=partial_collection")
-Runner.run(BasePostController, N, 'template', "/?action=show_template")
-# Runner.run(BasePostController.action(:many_partials), N, 'index')
-# 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, N, 'index', "/?action=index", false)
+Runner.run(BasePostController, N, 'partial', "/?action=partial", false)
+Runner.run(BasePostController, N, 'many partials', "/?action=many_partials", false)
+Runner.run(BasePostController, N, 'collection', "/?action=partial_collection", false)
+Runner.run(BasePostController, N, 'template', "/?action=show_template", false)
+
+(ENV["M"] || 1).to_i.times do
+ Runner.run(BasePostController, N, 'index', "/?action=index")
+ Runner.run(BasePostController, N, 'partial', "/?action=partial")
+ Runner.run(BasePostController, N, 'many partials', "/?action=many_partials")
+ Runner.run(BasePostController, N, 'collection', "/?action=partial_collection")
+ Runner.run(BasePostController, N, 'template', "/?action=show_template")
+end
+ # Runner.run(BasePostController.action(:many_partials), N, 'index')
+ # 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')
Please sign in to comment.
Something went wrong with that request. Please try again.