mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Compare Base with Http
This commit is contained in:
parent
6e039e863a
commit
bdb61c1dad
1 changed files with 24 additions and 13 deletions
|
@ -7,12 +7,6 @@ require 'action_controller'
|
||||||
require 'action_controller/new_base' if ENV['NEW']
|
require 'action_controller/new_base' if ENV['NEW']
|
||||||
require 'benchmark'
|
require 'benchmark'
|
||||||
|
|
||||||
class BaseController < ActionController::Base
|
|
||||||
def index
|
|
||||||
render :text => ''
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Runner
|
class Runner
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
@app = app
|
@app = app
|
||||||
|
@ -29,14 +23,31 @@ class Runner
|
||||||
response[2].each { |part| out.puts part }
|
response[2].each { |part| out.puts part }
|
||||||
out.puts '---'
|
out.puts '---'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
n = (ENV['N'] || 1000).to_i
|
|
||||||
input = StringIO.new('')
|
|
||||||
|
|
||||||
elapsed = Benchmark.realtime do
|
N = (ENV['N'] || 1000).to_i
|
||||||
Runner.new(BaseController.action(:index)).
|
|
||||||
call('n' => n, 'rack.input' => input, 'rack.errors' => $stdout)
|
class BasePostController < ActionController::Base
|
||||||
|
def index
|
||||||
|
render :text => ''
|
||||||
|
end
|
||||||
|
|
||||||
|
Runner.run(action(:index), N)
|
||||||
|
end
|
||||||
|
|
||||||
|
if ActionController.const_defined?(:Http)
|
||||||
|
class HttpPostController < ActionController::Http
|
||||||
|
def index
|
||||||
|
self.response_body = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
Runner.run(action(:index), N)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
puts "%dms elapsed, %d req/sec, %.2f msec/req" %
|
|
||||||
[1000 * elapsed, n / elapsed, 1000 * elapsed / n]
|
|
||||||
|
|
Loading…
Reference in a new issue