diff options
Diffstat (limited to 'actionpack/examples/minimal.rb')
-rw-r--r-- | actionpack/examples/minimal.rb | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/actionpack/examples/minimal.rb b/actionpack/examples/minimal.rb index 84a8499daf..e2d112648c 100644 --- a/actionpack/examples/minimal.rb +++ b/actionpack/examples/minimal.rb @@ -1,34 +1,53 @@ +# Pass NEW=1 to run with the new Base +ENV['RAILS_ENV'] ||= 'production' +ENV['NO_RELOAD'] ||= '1' + $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" require 'action_controller' require 'action_controller/new_base' if ENV['NEW'] require 'benchmark' -class BaseController < ActionController::Base - def index - render :text => '' +class Runner + def initialize(app) + @app = app end -end -n = (ENV['N'] || 10000).to_i -input = StringIO.new('') + def call(env) + env['n'].to_i.times { @app.call(env) } + @app.call(env).tap { |response| report(env, response) } + end + + def report(env, response) + out = env['rack.errors'] + out.puts response[0], response[1].to_yaml, '---' + response[2].each { |part| out.puts part } + out.puts '---' + end -def call_index(controller, input, n) - n.times do - controller.action(:index).call({ 'rack.input' => input }) + def self.run(app, n) + env = { 'n' => n, 'rack.input' => StringIO.new(''), 'rack.errors' => $stdout } + t = Benchmark.realtime { new(app).call(env) } + puts "%d ms / %d req = %d usec/req" % [10**3 * t, n, 10**6 * t / n] end +end + - puts controller.name - status, headers, body = controller.action(:index).call({ 'rack.input' => input }) +N = (ENV['N'] || 1000).to_i - puts status - puts headers.to_yaml - puts '---' - body.each do |part| - puts part +class BasePostController < ActionController::Base + def index + render :text => '' end - puts '---' + + Runner.run(action(:index), N) end -elapsed = Benchmark.realtime { call_index BaseController, input, n } +if ActionController.const_defined?(:Http) + class HttpPostController < ActionController::Http + def index + self.response_body = '' + end -puts "%dms elapsed, %d requests/sec" % [1000 * elapsed, n / elapsed] + Runner.run(action(:index), N) + end +end |