diff --git a/test/benchmark.rb b/test/benchmark.rb index c08f59c86e..2bb8160d1a 100755 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -14,19 +14,11 @@ require File.dirname(__FILE__) + '/../lib/haml' require File.dirname(__FILE__) + '/linked_rails' %w[sass rubygems erb erubis markaby active_support action_controller - action_view haml/template].each(&method(:require)) - -begin - require 'benchwarmer' -rescue LoadError - # Since it's not as simple as gem install at the time of writing, - # we need to direct folks to the benchwarmer gem. - raise "The Haml benchmarks require the benchwarmer gem, available from http://github.com/wycats/benchwarmer" -end + action_view action_pack haml/template rbench].each {|dep| require(dep)} def view unless ActionView::Base.instance_methods.include? 'finder' - return ActionView::Base.new(File.dirname(__FILE__), vars) + return ActionView::Base.new(File.dirname(__FILE__), {}) end # Rails >=2.1.0 @@ -35,9 +27,15 @@ def view base end -Benchmark.warmer(times) do - columns :haml, :erb, :erubis, :mab - titles :haml => "Haml", :erb => "ERB", :erubis => "Erubis", :mab => "Markaby" +def render(view, file) + view.render :file => file +end + +RBench.run(times) do + column :haml, :title => "Haml" + column :haml_ugly, :title => "Haml :ugly" + column :erb, :title => "ERB" + column :erubis, :title => "Erubis" template_name = 'standard' directory = File.dirname(__FILE__) + '/haml' @@ -45,49 +43,56 @@ def view erb_template = File.read("#{directory}/rhtml/#{template_name}.rhtml") markaby_template = File.read("#{directory}/markaby/#{template_name}.mab") - report "Uncached" do - haml { Haml::Engine.new(haml_template).render } - erb { ERB.new(erb_template, nil, '-').result } - erubis { Erubis::Eruby.new(erb_template).result } - mab { Markaby::Template.new(markaby_template).render } - end - report "Cached" do obj = Object.new Haml::Engine.new(haml_template).def_method(obj, :haml) + Haml::Engine.new(haml_template, :ugly => true).def_method(obj, :haml_ugly) Erubis::Eruby.new(erb_template).def_method(obj, :erubis) obj.instance_eval("def erb; #{ERB.new(erb_template, nil, '-').src}; end") - haml { obj.haml } - erb { obj.erb } - erubis { obj.erubis } + haml { obj.haml } + haml_ugly { obj.haml_ugly } + erb { obj.erb } + erubis { obj.erubis } end report "ActionView" do @base = view + @base.unmemoize_all + Haml::Template.options[:ugly] = false # To cache the template - @base.render 'haml/templates/standard' - @base.render 'haml/rhtml/standard' + render @base, 'haml/templates/standard' + render @base, 'haml/rhtml/standard' + + haml { render @base, 'haml/templates/standard' } + erb { render @base, 'haml/rhtml/standard' } - haml { @base.render 'haml/templates/standard' } - erb { @base.render 'haml/rhtml/standard' } + Haml::Template.options[:ugly] = true + render @base, 'haml/templates/standard_ugly' + haml_ugly { render @base, 'haml/templates/standard_ugly' } end report "ActionView with deep partials" do @base = view + @base.unmemoize_all + Haml::Template.options[:ugly] = false # To cache the template - @base.render 'haml/templates/action_view' - @base.render 'haml/rhtml/action_view' + render @base, 'haml/templates/action_view' + render @base, 'haml/rhtml/action_view' + + haml { render @base, 'haml/templates/action_view' } + erb { render @base, 'haml/rhtml/action_view' } - haml { @base.render 'haml/templates/action_view' } - erb { @base.render 'haml/rhtml/action_view' } + Haml::Template.options[:ugly] = true + render @base, 'haml/templates/action_view_ugly' + haml_ugly { render @base, 'haml/templates/action_view_ugly' } end end -Benchmark.warmer(times) do +RBench.run(times) do sass_template = File.read("#{File.dirname(__FILE__)}/sass/templates/complex.sass") report("Sass") { Sass::Engine.new(sass_template).render } diff --git a/test/haml/templates/_av_partial_1_ugly.haml b/test/haml/templates/_av_partial_1_ugly.haml new file mode 100644 index 0000000000..73e0ca7ac3 --- /dev/null +++ b/test/haml/templates/_av_partial_1_ugly.haml @@ -0,0 +1,9 @@ +%h2 This is a pretty complicated partial +.partial + %p It has several nested partials, + %ul + - 5.times do + %li + %strong Partial: + - @nesting = 5 + = render :partial => 'haml/templates/av_partial_2_ugly' \ No newline at end of file diff --git a/test/haml/templates/_av_partial_2_ugly.haml b/test/haml/templates/_av_partial_2_ugly.haml new file mode 100644 index 0000000000..088a3c366f --- /dev/null +++ b/test/haml/templates/_av_partial_2_ugly.haml @@ -0,0 +1,5 @@ +- @nesting -= 1 +.partial{:level => @nesting} + %h3 This is a crazy deep-nested partial. + %p== Nesting level #{@nesting} + = render :partial => 'haml/templates/av_partial_2_ugly' if @nesting > 0 \ No newline at end of file diff --git a/test/haml/templates/action_view_ugly.haml b/test/haml/templates/action_view_ugly.haml new file mode 100644 index 0000000000..5f0551ed9b --- /dev/null +++ b/test/haml/templates/action_view_ugly.haml @@ -0,0 +1,47 @@ +!!! +%html{html_attrs} + %head + %title Hampton Catlin Is Totally Awesome + %meta{"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8"} + %body + %h1 + This is very much like the standard template, + except that it has some ActionView-specific stuff. + It's only used for benchmarking. + .crazy_partials= render :partial => 'haml/templates/av_partial_1_ugly' + / You're In my house now! + .header + Yes, ladies and gentileman. He is just that egotistical. + Fantastic! This should be multi-line output + The question is if this would translate! Ahah! + = 1 + 9 + 8 + 2 #numbers should work and this should be ignored + #body= " Quotes should be loved! Just like people!" + - 120.times do |number| + - number + Wow.| + %p + = "Holy cow " + | + "multiline " + | + "tags! " + | + "A pipe (|) even!" | + = [1, 2, 3].collect { |n| "PipesIgnored|" } + = [1, 2, 3].collect { |n| | + n.to_s | + }.join("|") | + %div.silent + - foo = String.new + - foo << "this" + - foo << " shouldn't" + - foo << " evaluate" + = foo + " but now it should!" + -# Woah crap a comment! + + -# That was a line that shouldn't close everything. + %ul.really.cool + - ('a'..'f').each do |a| + %li= a + #combo.of_divs_with_underscore= @should_eval = "with this text" + = [ 104, 101, 108, 108, 111 ].map do |byte| + - byte.chr + .footer + %strong.shout= "This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid. \nSo, I'm just making it *really* long. God, I hope this works" diff --git a/test/haml/templates/standard_ugly.haml b/test/haml/templates/standard_ugly.haml new file mode 120000 index 0000000000..373b5e2c74 --- /dev/null +++ b/test/haml/templates/standard_ugly.haml @@ -0,0 +1 @@ +standard.haml \ No newline at end of file