From 29bd8f7b8975bc0442f0b63e7da077f9a3f22dc6 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 13 May 2009 16:15:18 -0700 Subject: Simple example for require profiling --- actionpack/examples/simple.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 actionpack/examples/simple.rb (limited to 'actionpack') diff --git a/actionpack/examples/simple.rb b/actionpack/examples/simple.rb new file mode 100644 index 0000000000..4ecb824688 --- /dev/null +++ b/actionpack/examples/simple.rb @@ -0,0 +1,17 @@ +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" +require 'action_controller' + +class PeopleController < ActionController::Base + def index + head :ok + end +end + +status, headers, body = PeopleController.action(:index).call({ 'rack.input' => StringIO.new('') }) + +puts status +puts headers.to_yaml +puts '---' +body.each do |part| + puts part +end -- cgit v1.2.3 From 5dd29c466c38a1bc395da579fd4b22c5e5a8e9fd Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 13 May 2009 16:15:37 -0700 Subject: Cherry-picking Active Support extensions --- actionpack/lib/action_dispatch/http/status_codes.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/status_codes.rb b/actionpack/lib/action_dispatch/http/status_codes.rb index 830de2a6db..5bac842ec1 100644 --- a/actionpack/lib/action_dispatch/http/status_codes.rb +++ b/actionpack/lib/action_dispatch/http/status_codes.rb @@ -1,3 +1,5 @@ +require 'active_support/inflector' + module ActionDispatch module StatusCodes #:nodoc: STATUS_CODES = Rack::Utils::HTTP_STATUS_CODES.merge({ @@ -16,7 +18,7 @@ module ActionDispatch # :created or :not_implemented) into its corresponding HTTP status # code (like 200 or 501). SYMBOL_TO_STATUS_CODE = STATUS_CODES.inject({}) { |hash, (code, message)| - hash[message.gsub(/ /, "").underscore.to_sym] = code + hash[ActiveSupport::Inflector.underscore(message.gsub(/ /, "")).to_sym] = code hash }.freeze @@ -37,4 +39,4 @@ module ActionDispatch end end end -end \ No newline at end of file +end -- cgit v1.2.3 From c286952050e8fe16b0f6d64ba0687b52cc8f2ae1 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 14 May 2009 01:56:07 -0700 Subject: Minimal base/new_base comparison --- actionpack/examples/minimal.rb | 34 ++++++++++++++++++++++ actionpack/examples/simple.rb | 17 ----------- actionpack/lib/action_controller/abstract/base.rb | 6 ++-- .../lib/action_controller/abstract/logger.rb | 4 ++- actionpack/lib/action_controller/new_base/http.rb | 5 +++- actionpack/lib/action_controller/routing.rb | 5 ++++ 6 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 actionpack/examples/minimal.rb delete mode 100644 actionpack/examples/simple.rb (limited to 'actionpack') diff --git a/actionpack/examples/minimal.rb b/actionpack/examples/minimal.rb new file mode 100644 index 0000000000..84a8499daf --- /dev/null +++ b/actionpack/examples/minimal.rb @@ -0,0 +1,34 @@ +$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 => '' + end +end + +n = (ENV['N'] || 10000).to_i +input = StringIO.new('') + +def call_index(controller, input, n) + n.times do + controller.action(:index).call({ 'rack.input' => input }) + end + + puts controller.name + status, headers, body = controller.action(:index).call({ 'rack.input' => input }) + + puts status + puts headers.to_yaml + puts '---' + body.each do |part| + puts part + end + puts '---' +end + +elapsed = Benchmark.realtime { call_index BaseController, input, n } + +puts "%dms elapsed, %d requests/sec" % [1000 * elapsed, n / elapsed] diff --git a/actionpack/examples/simple.rb b/actionpack/examples/simple.rb deleted file mode 100644 index 4ecb824688..0000000000 --- a/actionpack/examples/simple.rb +++ /dev/null @@ -1,17 +0,0 @@ -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" -require 'action_controller' - -class PeopleController < ActionController::Base - def index - head :ok - end -end - -status, headers, body = PeopleController.action(:index).call({ 'rack.input' => StringIO.new('') }) - -puts status -puts headers.to_yaml -puts '---' -body.each do |part| - puts part -end diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb index c9e1081b23..4b8d953643 100644 --- a/actionpack/lib/action_controller/abstract/base.rb +++ b/actionpack/lib/action_controller/abstract/base.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/module/attr_internal' + module AbstractController class Error < StandardError; end @@ -89,7 +91,7 @@ module AbstractController # you must handle it by also overriding process_action and # handling the case. def respond_to_action?(action_name) - action_methods.include?(action_name) || respond_to?(:action_missing, true) + action_methods.include?(action_name.to_s) || respond_to?(:action_missing, true) end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/abstract/logger.rb b/actionpack/lib/action_controller/abstract/logger.rb index 5fb78f1755..b154be754b 100644 --- a/actionpack/lib/action_controller/abstract/logger.rb +++ b/actionpack/lib/action_controller/abstract/logger.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/class/attribute_accessors' + module AbstractController module Logger extend ActiveSupport::DependencyModule @@ -6,4 +8,4 @@ module AbstractController cattr_accessor :logger end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/new_base/http.rb b/actionpack/lib/action_controller/new_base/http.rb index fb6041a04e..6852eb200a 100644 --- a/actionpack/lib/action_controller/new_base/http.rb +++ b/actionpack/lib/action_controller/new_base/http.rb @@ -1,3 +1,6 @@ +require 'action_controller/abstract' +require 'active_support/core_ext/module/delegation' + module ActionController class Http < AbstractController::Base abstract! @@ -57,7 +60,7 @@ module ActionController def self.action(name) @actions ||= {} - @actions[name] ||= proc do |env| + @actions[name.to_s] ||= proc do |env| new.call(name, env) end end diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index c0eb61340b..7edd379bc0 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -1,5 +1,10 @@ require 'cgi' require 'uri' +require 'set' + +require 'active_support/core_ext/module/aliasing' +require 'active_support/core_ext/module/attribute_accessors' + require 'action_controller/routing/optimisations' require 'action_controller/routing/routing_ext' require 'action_controller/routing/route' -- cgit v1.2.3