aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/examples
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-05-23 19:00:06 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-05-23 19:30:18 -0700
commita78b0a40c62600767d6ce75ba05bc86d401ad94c (patch)
treea7354971ba0d91d25a7ee9ae32350c29348ae685 /actionpack/examples
parent4e3fd23e311cd1773e62e7971f0f47af05d5000a (diff)
downloadrails-a78b0a40c62600767d6ce75ba05bc86d401ad94c.tar.gz
rails-a78b0a40c62600767d6ce75ba05bc86d401ad94c.tar.bz2
rails-a78b0a40c62600767d6ce75ba05bc86d401ad94c.zip
runner class
Diffstat (limited to 'actionpack/examples')
-rw-r--r--actionpack/examples/minimal.rb40
1 files changed, 24 insertions, 16 deletions
diff --git a/actionpack/examples/minimal.rb b/actionpack/examples/minimal.rb
index 76668b375d..0fc527445e 100644
--- a/actionpack/examples/minimal.rb
+++ b/actionpack/examples/minimal.rb
@@ -1,3 +1,7 @@
+# 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']
@@ -9,26 +13,30 @@ class BaseController < ActionController::Base
end
end
-n = (ENV['N'] || 1000).to_i
-input = StringIO.new('')
-
-def call_index(controller, input, n)
- n.times do
- controller.action(:index).call({ 'rack.input' => input })
+class Runner
+ def initialize(app)
+ @app = app
end
- puts controller.name
- status, headers, body = controller.action(:index).call({ 'rack.input' => input })
+ def call(env)
+ env['n'].to_i.times { @app.call(env) }
+ @app.call(env).tap { |response| report(env, response) }
+ end
- puts status
- puts headers.to_yaml
- puts '---'
- body.each do |part|
- puts part
+ 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
- puts '---'
end
-elapsed = Benchmark.realtime { call_index BaseController, input, n }
+n = (ENV['N'] || 1000).to_i
+input = StringIO.new('')
-puts "%dms elapsed, %d requests/sec" % [1000 * elapsed, n / elapsed]
+elapsed = Benchmark.realtime do
+ Runner.new(BaseController.action(:index)).
+ call('n' => n, 'rack.input' => input, 'rack.errors' => $stdout)
+end
+puts "%dms elapsed, %d req/sec, %.2f msec/req" %
+ [1000 * elapsed, n / elapsed, 1000 * elapsed / n]