From 04d4537cd40d0415d15af4395213632735c8683f Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sun, 9 Aug 2009 07:14:24 -0300 Subject: This change causes some failing tests, but it should be possible to make them pass with minimal performance impact. --- actionpack/examples/minimal.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'actionpack/examples/minimal.rb') diff --git a/actionpack/examples/minimal.rb b/actionpack/examples/minimal.rb index a9015da053..b3733b487b 100644 --- a/actionpack/examples/minimal.rb +++ b/actionpack/examples/minimal.rb @@ -91,6 +91,8 @@ class HttpPostController < ActionController::Metal end end +ActionController::Base.use_accept_header = false + unless ENV["PROFILE"] Runner.run(BasePostController.action(:overhead), N, 'overhead', false) Runner.run(BasePostController.action(:index), N, 'index', false) @@ -108,10 +110,10 @@ unless ENV["PROFILE"] Runner.run(BasePostController.action(:show_template), N, 'template') end else - Runner.run(BasePostController.action(:many_partials), N, 'many_partials') + Runner.run(BasePostController.action(ENV["PROFILE"].to_sym), N, ENV["PROFILE"]) require "ruby-prof" RubyProf.start - Runner.run(BasePostController.action(:many_partials), N, 'many_partials') + Runner.run(BasePostController.action(ENV["PROFILE"].to_sym), N, ENV["PROFILE"]) result = RubyProf.stop printer = RubyProf::CallStackPrinter.new(result) printer.print(File.open("output.html", "w")) -- cgit v1.2.3 From bef7576c09bbd51aeeb8e83b4cf24a994a0256b0 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sun, 9 Aug 2009 09:59:54 -0300 Subject: Add a few more benches --- actionpack/examples/minimal.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'actionpack/examples/minimal.rb') diff --git a/actionpack/examples/minimal.rb b/actionpack/examples/minimal.rb index b3733b487b..c4e5ffd36e 100644 --- a/actionpack/examples/minimal.rb +++ b/actionpack/examples/minimal.rb @@ -73,10 +73,18 @@ class BasePostController < ActionController::Base render :partial => "/many_partials" end + def hundred_partials + render :partial => "/hundred_partials" + end + def partial_collection render :partial => "/collection", :collection => [1,2,3,4,5,6,7,8,9,10] end + def large_collection + render :partial => "/collection", :collection => (1...100).to_a + end + def show_template render :template => "template" end @@ -99,6 +107,8 @@ unless ENV["PROFILE"] Runner.run(BasePostController.action(:partial), N, 'partial', false) Runner.run(BasePostController.action(:many_partials), N, 'many_partials', false) Runner.run(BasePostController.action(:partial_collection), N, 'collection', false) + Runner.run(BasePostController.action(:hundred_partials), N, 'hundred_partials', false) + Runner.run(BasePostController.action(:large_collection), N, 'large_collection', false) Runner.run(BasePostController.action(:show_template), N, 'template', false) (ENV["M"] || 1).to_i.times do @@ -107,6 +117,8 @@ unless ENV["PROFILE"] Runner.run(BasePostController.action(:partial), N, 'partial') Runner.run(BasePostController.action(:many_partials), N, 'many_partials') Runner.run(BasePostController.action(:partial_collection), N, 'collection') + Runner.run(BasePostController.action(:hundred_partials), N, 'hundred_partials') + Runner.run(BasePostController.action(:large_collection), N, 'large_collection') Runner.run(BasePostController.action(:show_template), N, 'template') end else -- cgit v1.2.3 From 4945d8223964d4ccb3c0a0f4107f15ae1c6c4a09 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Mon, 10 Aug 2009 02:54:17 -0400 Subject: Further experimentation. Was able to cut the cost of rendering 100 partials in a collection in half. To discuss: What are the desired semantics (if any) for layouts in a collection. There are no tests for it at present, and I'm not sure if it's needed at all. Deprecated on this branch: `object` pointing at the current object in partials. You can still use the partial name, or use :as to achieve the same thing. This is obviously up for discussion. --- actionpack/examples/minimal.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/examples/minimal.rb') diff --git a/actionpack/examples/minimal.rb b/actionpack/examples/minimal.rb index c4e5ffd36e..90435d0b89 100644 --- a/actionpack/examples/minimal.rb +++ b/actionpack/examples/minimal.rb @@ -104,22 +104,22 @@ ActionController::Base.use_accept_header = false unless ENV["PROFILE"] Runner.run(BasePostController.action(:overhead), N, 'overhead', false) Runner.run(BasePostController.action(:index), N, 'index', false) + Runner.run(BasePostController.action(:show_template), N, 'template', false) Runner.run(BasePostController.action(:partial), N, 'partial', false) Runner.run(BasePostController.action(:many_partials), N, 'many_partials', false) Runner.run(BasePostController.action(:partial_collection), N, 'collection', false) Runner.run(BasePostController.action(:hundred_partials), N, 'hundred_partials', false) Runner.run(BasePostController.action(:large_collection), N, 'large_collection', false) - Runner.run(BasePostController.action(:show_template), N, 'template', false) (ENV["M"] || 1).to_i.times do Runner.run(BasePostController.action(:overhead), N, 'overhead') Runner.run(BasePostController.action(:index), N, 'index') + Runner.run(BasePostController.action(:show_template), N, 'template') Runner.run(BasePostController.action(:partial), N, 'partial') Runner.run(BasePostController.action(:many_partials), N, 'many_partials') Runner.run(BasePostController.action(:partial_collection), N, 'collection') Runner.run(BasePostController.action(:hundred_partials), N, 'hundred_partials') Runner.run(BasePostController.action(:large_collection), N, 'large_collection') - Runner.run(BasePostController.action(:show_template), N, 'template') end else Runner.run(BasePostController.action(ENV["PROFILE"].to_sym), N, ENV["PROFILE"]) -- cgit v1.2.3 From 945a7df9f8ad2986ba2351b331a9f7225dfaf61c Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Mon, 10 Aug 2009 03:28:21 -0400 Subject: Make large_collection 1,000 partials --- actionpack/examples/minimal.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'actionpack/examples/minimal.rb') diff --git a/actionpack/examples/minimal.rb b/actionpack/examples/minimal.rb index 90435d0b89..62b71de2cb 100644 --- a/actionpack/examples/minimal.rb +++ b/actionpack/examples/minimal.rb @@ -82,7 +82,7 @@ class BasePostController < ActionController::Base end def large_collection - render :partial => "/collection", :collection => (1...100).to_a + render :partial => "/collection", :collection => (1...1000).to_a end def show_template @@ -102,14 +102,14 @@ end ActionController::Base.use_accept_header = false unless ENV["PROFILE"] - Runner.run(BasePostController.action(:overhead), N, 'overhead', false) - Runner.run(BasePostController.action(:index), N, 'index', false) - Runner.run(BasePostController.action(:show_template), N, 'template', false) - Runner.run(BasePostController.action(:partial), N, 'partial', false) - Runner.run(BasePostController.action(:many_partials), N, 'many_partials', false) - Runner.run(BasePostController.action(:partial_collection), N, 'collection', false) - Runner.run(BasePostController.action(:hundred_partials), N, 'hundred_partials', false) - Runner.run(BasePostController.action(:large_collection), N, 'large_collection', false) + Runner.run(BasePostController.action(:overhead), 1, 'overhead', false) + Runner.run(BasePostController.action(:index), 1, 'index', false) + Runner.run(BasePostController.action(:show_template), 1, 'template', false) + Runner.run(BasePostController.action(:partial), 1, 'partial', false) + Runner.run(BasePostController.action(:many_partials), 1, 'many_partials', false) + Runner.run(BasePostController.action(:partial_collection), 1, 'collection', false) + Runner.run(BasePostController.action(:hundred_partials), 1, 'hundred_partials', false) + Runner.run(BasePostController.action(:large_collection), 1, 'large_collection', false) (ENV["M"] || 1).to_i.times do Runner.run(BasePostController.action(:overhead), N, 'overhead') @@ -122,7 +122,7 @@ unless ENV["PROFILE"] Runner.run(BasePostController.action(:large_collection), N, 'large_collection') end else - Runner.run(BasePostController.action(ENV["PROFILE"].to_sym), N, ENV["PROFILE"]) + Runner.run(BasePostController.action(ENV["PROFILE"].to_sym), 1, ENV["PROFILE"]) require "ruby-prof" RubyProf.start Runner.run(BasePostController.action(ENV["PROFILE"].to_sym), N, ENV["PROFILE"]) -- cgit v1.2.3 From 27e880729eeb058583b79ccf84a7577c434addfd Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Tue, 11 Aug 2009 16:49:27 -0700 Subject: Made benchmarks submodule so it's easier to keep in sync --- actionpack/examples | 1 + actionpack/examples/minimal.rb | 132 ----------------------------------------- 2 files changed, 1 insertion(+), 132 deletions(-) create mode 160000 actionpack/examples delete mode 100644 actionpack/examples/minimal.rb (limited to 'actionpack/examples/minimal.rb') diff --git a/actionpack/examples b/actionpack/examples new file mode 160000 index 0000000000..4e1327f06d --- /dev/null +++ b/actionpack/examples @@ -0,0 +1 @@ +Subproject commit 4e1327f06da6df1a1981d69c04e8d6463b38a4c1 diff --git a/actionpack/examples/minimal.rb b/actionpack/examples/minimal.rb deleted file mode 100644 index 62b71de2cb..0000000000 --- a/actionpack/examples/minimal.rb +++ /dev/null @@ -1,132 +0,0 @@ -# Pass NEW=1 to run with the new Base -ENV['RAILS_ENV'] ||= 'production' -ENV['NO_RELOAD'] ||= '1' - -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib" -require 'action_controller' -require 'action_controller/new_base' if ENV['NEW'] -require 'action_view' -require 'benchmark' - -class Runner - def initialize(app, output) - @app, @output = app, output - end - - def puts(*) - super if @output - 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) - return unless ENV["DEBUG"] - out = env['rack.errors'] - out.puts response[0], response[1].to_yaml, '---' - response[2].each { |part| out.puts part } - out.puts '---' - end - - def self.puts(*) - super if @output - end - - def self.run(app, n, label, output = true) - @output = output - puts label, '=' * label.size if label - env = Rack::MockRequest.env_for("/").merge('n' => n, 'rack.input' => StringIO.new(''), 'rack.errors' => $stdout) - t = Benchmark.realtime { new(app, output).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 - -module ActionController::Rails2Compatibility - instance_methods.each do |name| - remove_method name - end -end - -class BasePostController < ActionController::Base - append_view_path "#{File.dirname(__FILE__)}/views" - - def overhead - self.response_body = '' - end - - def index - render :text => '' - end - - def partial - render :partial => "/partial" - end - - def many_partials - render :partial => "/many_partials" - end - - def hundred_partials - render :partial => "/hundred_partials" - end - - def partial_collection - render :partial => "/collection", :collection => [1,2,3,4,5,6,7,8,9,10] - end - - def large_collection - render :partial => "/collection", :collection => (1...1000).to_a - end - - def show_template - render :template => "template" - end -end - -OK = [200, {}, []] -MetalPostController = lambda { OK } - -class HttpPostController < ActionController::Metal - def index - self.response_body = '' - end -end - -ActionController::Base.use_accept_header = false - -unless ENV["PROFILE"] - Runner.run(BasePostController.action(:overhead), 1, 'overhead', false) - Runner.run(BasePostController.action(:index), 1, 'index', false) - Runner.run(BasePostController.action(:show_template), 1, 'template', false) - Runner.run(BasePostController.action(:partial), 1, 'partial', false) - Runner.run(BasePostController.action(:many_partials), 1, 'many_partials', false) - Runner.run(BasePostController.action(:partial_collection), 1, 'collection', false) - Runner.run(BasePostController.action(:hundred_partials), 1, 'hundred_partials', false) - Runner.run(BasePostController.action(:large_collection), 1, 'large_collection', false) - - (ENV["M"] || 1).to_i.times do - Runner.run(BasePostController.action(:overhead), N, 'overhead') - Runner.run(BasePostController.action(:index), N, 'index') - Runner.run(BasePostController.action(:show_template), N, 'template') - Runner.run(BasePostController.action(:partial), N, 'partial') - Runner.run(BasePostController.action(:many_partials), N, 'many_partials') - Runner.run(BasePostController.action(:partial_collection), N, 'collection') - Runner.run(BasePostController.action(:hundred_partials), N, 'hundred_partials') - Runner.run(BasePostController.action(:large_collection), N, 'large_collection') - end -else - Runner.run(BasePostController.action(ENV["PROFILE"].to_sym), 1, ENV["PROFILE"]) - require "ruby-prof" - RubyProf.start - Runner.run(BasePostController.action(ENV["PROFILE"].to_sym), N, ENV["PROFILE"]) - result = RubyProf.stop - printer = RubyProf::CallStackPrinter.new(result) - printer.print(File.open("output.html", "w")) -end \ No newline at end of file -- cgit v1.2.3 From ba67e256b8bb3749090fcf7ccaff497ea006b1d1 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Tue, 11 Aug 2009 23:44:44 -0700 Subject: Remove submodule --- actionpack/examples | 1 - 1 file changed, 1 deletion(-) delete mode 160000 actionpack/examples (limited to 'actionpack/examples/minimal.rb') diff --git a/actionpack/examples b/actionpack/examples deleted file mode 160000 index 4e1327f06d..0000000000 --- a/actionpack/examples +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4e1327f06da6df1a1981d69c04e8d6463b38a4c1 -- cgit v1.2.3