aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/examples
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-05-29 16:06:21 -0500
committerJoshua Peek <josh@joshpeek.com>2009-05-29 16:06:21 -0500
commit69742ca8fa05509f7d7c5512cb6d8e002ecb3ab3 (patch)
tree044c2131cc87d21ee54027511aae2b7f2d2ae26a /actionpack/examples
parent5f3f100ce2d689480da85abc88e5e940cf90189e (diff)
parent5ec2c7dc29b36d85b2658465b8a979deb0529d7e (diff)
downloadrails-69742ca8fa05509f7d7c5512cb6d8e002ecb3ab3.tar.gz
rails-69742ca8fa05509f7d7c5512cb6d8e002ecb3ab3.tar.bz2
rails-69742ca8fa05509f7d7c5512cb6d8e002ecb3ab3.zip
Merge branch 'master' into active_model
Conflicts: activemodel/lib/active_model/core.rb activemodel/test/cases/state_machine/event_test.rb activemodel/test/cases/state_machine/state_transition_test.rb activerecord/lib/active_record/validations.rb activerecord/test/cases/validations/i18n_validation_test.rb activeresource/lib/active_resource.rb activeresource/test/abstract_unit.rb
Diffstat (limited to 'actionpack/examples')
-rw-r--r--actionpack/examples/minimal.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/actionpack/examples/minimal.rb b/actionpack/examples/minimal.rb
new file mode 100644
index 0000000000..9eb92cd8e7
--- /dev/null
+++ b/actionpack/examples/minimal.rb
@@ -0,0 +1,58 @@
+# 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 Runner
+ def initialize(app)
+ @app = app
+ end
+
+ 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 self.run(app, n, label = nil)
+ puts '=' * label.size, label, '=' * label.size if label
+ 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
+ end
+end
+
+
+N = (ENV['N'] || 1000).to_i
+
+class BasePostController < ActionController::Base
+ def index
+ render :text => ''
+ end
+end
+
+OK = [200, {}, []]
+MetalPostController = lambda { OK }
+
+if ActionController.const_defined?(:Http)
+ class HttpPostController < ActionController::Http
+ def index
+ self.response_body = ''
+ end
+ end
+end
+
+Runner.run(MetalPostController, N, 'metal')
+Runner.run(HttpPostController.action(:index), N, 'http') if defined? HttpPostController
+Runner.run(BasePostController.action(:index), N, 'base')