mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Backport benchmark.rb updates to stable.
This commit is contained in:
parent
a8fa047e71
commit
c9a74e21b5
5 changed files with 99 additions and 32 deletions
|
@ -14,19 +14,11 @@ end
|
||||||
require File.dirname(__FILE__) + '/../lib/haml'
|
require File.dirname(__FILE__) + '/../lib/haml'
|
||||||
require File.dirname(__FILE__) + '/linked_rails'
|
require File.dirname(__FILE__) + '/linked_rails'
|
||||||
%w[sass rubygems erb erubis markaby active_support action_controller
|
%w[sass rubygems erb erubis markaby active_support action_controller
|
||||||
action_view haml/template].each(&method(:require))
|
action_view action_pack haml/template rbench].each {|dep| require(dep)}
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def view
|
def view
|
||||||
unless ActionView::Base.instance_methods.include? 'finder'
|
unless ActionView::Base.instance_methods.include? 'finder'
|
||||||
return ActionView::Base.new(File.dirname(__FILE__), vars)
|
return ActionView::Base.new(File.dirname(__FILE__), {})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rails >=2.1.0
|
# Rails >=2.1.0
|
||||||
|
@ -35,9 +27,15 @@ def view
|
||||||
base
|
base
|
||||||
end
|
end
|
||||||
|
|
||||||
Benchmark.warmer(times) do
|
def render(view, file)
|
||||||
columns :haml, :erb, :erubis, :mab
|
view.render :file => file
|
||||||
titles :haml => "Haml", :erb => "ERB", :erubis => "Erubis", :mab => "Markaby"
|
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'
|
template_name = 'standard'
|
||||||
directory = File.dirname(__FILE__) + '/haml'
|
directory = File.dirname(__FILE__) + '/haml'
|
||||||
|
@ -45,49 +43,56 @@ Benchmark.warmer(times) do
|
||||||
erb_template = File.read("#{directory}/rhtml/#{template_name}.rhtml")
|
erb_template = File.read("#{directory}/rhtml/#{template_name}.rhtml")
|
||||||
markaby_template = File.read("#{directory}/markaby/#{template_name}.mab")
|
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
|
report "Cached" do
|
||||||
obj = Object.new
|
obj = Object.new
|
||||||
|
|
||||||
Haml::Engine.new(haml_template).def_method(obj, :haml)
|
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)
|
Erubis::Eruby.new(erb_template).def_method(obj, :erubis)
|
||||||
obj.instance_eval("def erb; #{ERB.new(erb_template, nil, '-').src}; end")
|
obj.instance_eval("def erb; #{ERB.new(erb_template, nil, '-').src}; end")
|
||||||
|
|
||||||
haml { obj.haml }
|
haml { obj.haml }
|
||||||
erb { obj.erb }
|
haml_ugly { obj.haml_ugly }
|
||||||
erubis { obj.erubis }
|
erb { obj.erb }
|
||||||
|
erubis { obj.erubis }
|
||||||
end
|
end
|
||||||
|
|
||||||
report "ActionView" do
|
report "ActionView" do
|
||||||
@base = view
|
@base = view
|
||||||
|
|
||||||
|
@base.unmemoize_all
|
||||||
|
Haml::Template.options[:ugly] = false
|
||||||
# To cache the template
|
# To cache the template
|
||||||
@base.render 'haml/templates/standard'
|
render @base, 'haml/templates/standard'
|
||||||
@base.render 'haml/rhtml/standard'
|
render @base, 'haml/rhtml/standard'
|
||||||
|
|
||||||
haml { @base.render 'haml/templates/standard' }
|
haml { render @base, 'haml/templates/standard' }
|
||||||
erb { @base.render 'haml/rhtml/standard' }
|
erb { render @base, 'haml/rhtml/standard' }
|
||||||
|
|
||||||
|
Haml::Template.options[:ugly] = true
|
||||||
|
render @base, 'haml/templates/standard_ugly'
|
||||||
|
haml_ugly { render @base, 'haml/templates/standard_ugly' }
|
||||||
end
|
end
|
||||||
|
|
||||||
report "ActionView with deep partials" do
|
report "ActionView with deep partials" do
|
||||||
@base = view
|
@base = view
|
||||||
|
|
||||||
|
@base.unmemoize_all
|
||||||
|
Haml::Template.options[:ugly] = false
|
||||||
# To cache the template
|
# To cache the template
|
||||||
@base.render 'haml/templates/action_view'
|
render @base, 'haml/templates/action_view'
|
||||||
@base.render 'haml/rhtml/action_view'
|
render @base, 'haml/rhtml/action_view'
|
||||||
|
|
||||||
haml { @base.render 'haml/templates/action_view' }
|
haml { render @base, 'haml/templates/action_view' }
|
||||||
erb { @base.render 'haml/rhtml/action_view' }
|
erb { render @base, '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
|
||||||
end
|
end
|
||||||
|
|
||||||
Benchmark.warmer(times) do
|
RBench.run(times) do
|
||||||
sass_template = File.read("#{File.dirname(__FILE__)}/sass/templates/complex.sass")
|
sass_template = File.read("#{File.dirname(__FILE__)}/sass/templates/complex.sass")
|
||||||
|
|
||||||
report("Sass") { Sass::Engine.new(sass_template).render }
|
report("Sass") { Sass::Engine.new(sass_template).render }
|
||||||
|
|
9
test/haml/templates/_av_partial_1_ugly.haml
Normal file
9
test/haml/templates/_av_partial_1_ugly.haml
Normal file
|
@ -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'
|
5
test/haml/templates/_av_partial_2_ugly.haml
Normal file
5
test/haml/templates/_av_partial_2_ugly.haml
Normal file
|
@ -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
|
47
test/haml/templates/action_view_ugly.haml
Normal file
47
test/haml/templates/action_view_ugly.haml
Normal file
|
@ -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"
|
1
test/haml/templates/standard_ugly.haml
Symbolic link
1
test/haml/templates/standard_ugly.haml
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
standard.haml
|
Loading…
Reference in a new issue