mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
More rigorous ActionView benchmarks.
git-svn-id: svn://hamptoncatlin.com/haml/trunk@658 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
8be9a850bb
commit
f0de64c0fc
8 changed files with 146 additions and 6 deletions
|
@ -46,9 +46,7 @@ module Haml
|
|||
# with <tt>local_assigns</tt> available as local variables within the template.
|
||||
# Returns the result as a string.
|
||||
def render(template, local_assigns={})
|
||||
@view.instance_eval do
|
||||
evaluate_assigns
|
||||
end
|
||||
@view.send(:evaluate_assigns)
|
||||
|
||||
options = @@options.dup
|
||||
locals = options[:locals] || {}
|
||||
|
@ -67,7 +65,6 @@ module Haml
|
|||
end
|
||||
|
||||
engine.to_html(@view) { |*args| yield_proc.call(*args) }
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -72,8 +72,8 @@ module Haml
|
|||
ActionView::Base.register_template_handler("haml", Haml::Template)
|
||||
@base = ActionView::Base.new(File.dirname(__FILE__))
|
||||
times = Benchmark.bmbm do |b|
|
||||
b.report("haml:") { runs.times { @base.render 'haml/templates/standard' } }
|
||||
b.report("erb:") { runs.times { @base.render 'haml/rhtml/standard' } }
|
||||
b.report("haml:") { runs.times { @base.render 'haml/templates/action_view' } }
|
||||
b.report("erb:") { runs.times { @base.render 'haml/rhtml/action_view' } }
|
||||
end
|
||||
|
||||
print_result["ERB", 1]
|
||||
|
|
12
test/haml/rhtml/_av_partial_1.rhtml
Normal file
12
test/haml/rhtml/_av_partial_1.rhtml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<h2>This is a pretty complicated partial</h2>
|
||||
<div class="partial">
|
||||
<p>It has several nested partials,</p>
|
||||
<ul>
|
||||
<% 5.times do %>
|
||||
<li>
|
||||
<strong>Partial:</strong>
|
||||
<% @nesting = 5 %>
|
||||
<%= render :partial => 'haml/rhtml/av_partial_2' %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
8
test/haml/rhtml/_av_partial_2.rhtml
Normal file
8
test/haml/rhtml/_av_partial_2.rhtml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<% @nesting -= 1 %>
|
||||
<div class="partial" level="<%= @nesting %>">
|
||||
<h3>This is a crazy deep-nested partial.</h3>
|
||||
<p>Nesting level <%= @nesting %></p>
|
||||
<% if @nesting > 0 %>
|
||||
<%= render :partial => 'haml/rhtml/av_partial_2' %>
|
||||
<% end %>
|
||||
</div>
|
62
test/haml/rhtml/action_view.rhtml
Normal file
62
test/haml/rhtml/action_view.rhtml
Normal file
|
@ -0,0 +1,62 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en-US'>
|
||||
<head>
|
||||
<title>Hampton Catlin Is Totally Awesome</title>
|
||||
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
This is very much like the standard template,
|
||||
except that it has some ActionView-specific stuff.
|
||||
It's only used for benchmarking.
|
||||
</h1>
|
||||
<div class="crazy_partials">
|
||||
<%= render :partial => 'haml/rhtml/av_partial_1' %>
|
||||
</div>
|
||||
<!-- You're In my house now! -->
|
||||
<div class='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 %>
|
||||
</div>
|
||||
<% 120.times do |number| -%>
|
||||
<%= number %>
|
||||
<% end -%>
|
||||
<div id='body'><%= " Quotes should be loved! Just like people!" %></div>
|
||||
Wow.
|
||||
<p>
|
||||
<%= "Holy cow " +
|
||||
"multiline " +
|
||||
"tags! " +
|
||||
"A pipe (|) even!" %>
|
||||
<%= [1, 2, 3].collect { |n| "PipesIgnored|" } %>
|
||||
<%= [1, 2, 3].collect { |n|
|
||||
n.to_s
|
||||
}.join("|") %>
|
||||
</p>
|
||||
<div class='silent'>
|
||||
<% foo = String.new
|
||||
foo << "this"
|
||||
foo << " shouldn't"
|
||||
foo << " evaluate" %>
|
||||
<%= foo + "but now it should!" %>
|
||||
<%# Woah crap a comment! %>
|
||||
</div>
|
||||
<ul class='really cool'>
|
||||
<% ('a'..'f').each do |a|%>
|
||||
<li><%= a %>
|
||||
<% end %>
|
||||
<div class='of_divs_with_underscore' id='combo'><%= @should_eval = "with this text" %></div>
|
||||
<%= [ 104, 101, 108, 108, 111 ].map do |byte|
|
||||
byte.chr
|
||||
end %>
|
||||
<div class='footer'>
|
||||
<strong class='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.\n" +
|
||||
" So, I'm just making it *really* long. God, I hope this works" %>
|
||||
</strong>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
9
test/haml/templates/_av_partial_1.haml
Normal file
9
test/haml/templates/_av_partial_1.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'
|
5
test/haml/templates/_av_partial_2.haml
Normal file
5
test/haml/templates/_av_partial_2.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' if @nesting > 0
|
47
test/haml/templates/action_view.haml
Normal file
47
test/haml/templates/action_view.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'
|
||||
/ 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"
|
Loading…
Add table
Reference in a new issue