1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/examples/minimal.rb

59 lines
1.4 KiB
Ruby
Raw Normal View History

2009-05-23 22:00:06 -04:00
# Pass NEW=1 to run with the new Base
ENV['RAILS_ENV'] ||= 'production'
ENV['NO_RELOAD'] ||= '1'
2009-05-14 04:56:07 -04:00
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
require 'action_controller'
require 'action_controller/new_base' if ENV['NEW']
require 'benchmark'
2009-05-23 22:00:06 -04:00
class Runner
def initialize(app)
@app = app
2009-05-14 04:56:07 -04:00
end
2009-05-23 22:00:06 -04:00
def call(env)
env['n'].to_i.times { @app.call(env) }
@app.call(env).tap { |response| report(env, response) }
end
2009-05-14 04:56:07 -04:00
2009-05-23 22:00:06 -04:00
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 '---'
2009-05-14 04:56:07 -04:00
end
2009-05-24 20:34:40 -04:00
def self.run(app, n, label = nil)
puts '=' * label.size, label, '=' * label.size if label
2009-05-24 20:34:40 -04:00
env = { 'n' => n, 'rack.input' => StringIO.new(''), 'rack.errors' => $stdout }
t = Benchmark.realtime { new(app).call(env) }
puts "%d ms / %d req = %.1f usec/req" % [10**3 * t, n, 10**6 * t / n]
puts
2009-05-24 20:34:40 -04:00
end
end
N = (ENV['N'] || 1000).to_i
class BasePostController < ActionController::Base
def index
render :text => ''
end
2009-05-14 04:56:07 -04:00
end
OK = [200, {}, []]
MetalPostController = lambda { OK }
2009-05-24 20:34:40 -04:00
if ActionController.const_defined?(:Http)
class HttpPostController < ActionController::Http
def index
self.response_body = ''
end
end
2009-05-23 22:00:06 -04:00
end
Runner.run(MetalPostController, N, 'metal')
Runner.run(HttpPostController.action(:index), N, 'http') if defined? HttpPostController
Runner.run(BasePostController.action(:index), N, 'base')