Permalink
Browse files

Added Erb, Erubis, Haml benchmarks

  • Loading branch information...
1 parent 6230693 commit cf586b633023dab3721937535d0dee88ac30dd43 @hosiawak hosiawak committed Feb 28, 2013
@@ -0,0 +1,16 @@
+require 'benchmark'
+require 'benchmark/ips'
+
+require 'erb'
+
+erb_template = File.read(File.join(File.dirname(__FILE__), 'template.erb'))
+engine = ERB.new(erb_template, nil, '-')
+
+Benchmark.ips do |x|
+ x.report "ERB result" do
+ engine.result
+ end
+
+end
+
+
@@ -0,0 +1,55 @@
+<!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' lang='en-US'>
+ <head>
+ <title>JOdsj aoiJ soijsd osj OIJsj OIsow JOsiw</title>
+ <meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
+ </head>
+ <body>
+ <!-- Paoij 08s sjsoijs 9s s! -->
+ <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 code="<%= 1 + 2 %>">
+ <%= "Holy cow " +
+ "multiline " +
+ "tags! " +
+ "A pipe (|) even!" %>
+ <%= [1, 2, 3].collect { |n| "PipesIgnored|" }.join %>
+ <%= [1, 2, 3].collect { |n|
+ n.to_s
+ }.join("|") %>
+ </p>
+ <% bar = 17 %>
+ <div class='silent' foo="<%= bar %>">
+ <% 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 %></li>
+ <% end %>
+ <div class='of_divs_with_underscore' id='combo'><%= @should_eval = "with this text" %></div>
+ <%= "foo".each_line do |line|
+ nil
+ 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>
@@ -0,0 +1,32 @@
+require 'benchmark'
+require 'benchmark/ips'
+
+require 'rubygems'
+require 'rubygems/commands/install_command'
+
+ERUBIS_VERSION = '2.7.0'
+
+begin
+ gem 'erubis', ERUBIS_VERSION
+ require 'erubis'
+rescue LoadError
+ inst = Gem::DependencyInstaller.new
+ inst.install 'erubis', ERUBIS_VERSION
+ gem 'erubis', ERUBIS_VERSION
+ require 'erubis'
+end
+
+erb_template = File.read(File.join(File.dirname(__FILE__), 'template.erb'))
+eruby = Erubis::Eruby.new(erb_template)
+feruby = Erubis::FastEruby.new(erb_template)
+
+Benchmark.ips do |x|
+ x.report "Eruby result" do
+ eruby.result
+ end
+ x.report "FastEruby result" do
+ feruby.result
+ end
+end
+
+
@@ -0,0 +1,55 @@
+<!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' lang='en-US'>
+ <head>
+ <title>JOdsj aoiJ soijsd osj OIJsj OIsow JOsiw</title>
+ <meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
+ </head>
+ <body>
+ <!-- Paoij 08s sjsoijs 9s s! -->
+ <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 code="<%= 1 + 2 %>">
+ <%= "Holy cow " +
+ "multiline " +
+ "tags! " +
+ "A pipe (|) even!" %>
+ <%= [1, 2, 3].collect { |n| "PipesIgnored|" }.join %>
+ <%= [1, 2, 3].collect { |n|
+ n.to_s
+ }.join("|") %>
+ </p>
+ <% bar = 17 %>
+ <div class='silent' foo="<%= bar %>">
+ <% 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 %></li>
+ <% end %>
+ <div class='of_divs_with_underscore' id='combo'><%= @should_eval = "with this text" %></div>
+ <%= "foo".each_line do |line|
+ nil
+ 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>
@@ -0,0 +1,27 @@
+require 'benchmark'
+require 'benchmark/ips'
+
+require 'rubygems'
+require 'rubygems/commands/install_command'
+
+HAML_VERSION = '4.0.0'
+
+begin
+ gem 'haml', HAML_VERSION
+ require 'haml'
+rescue LoadError
+ inst = Gem::DependencyInstaller.new
+ inst.install 'haml', HAML_VERSION
+ gem 'haml', HAML_VERSION
+ require 'haml'
+end
+
+engine = Haml::Engine.new(File.read(File.join(File.dirname(__FILE__), 'template.haml')))
+
+Benchmark.ips do |x|
+ x.report "Haml render" do
+ engine.render
+ end
+
+end
+
@@ -0,0 +1,43 @@
+!!!
+%html{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en-US", "lang" => "en-US"}
+ %head
+ %title iH s98sh ssh suish sihsiush 9shsu
+ %meta{"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8"}
+ %body
+ / 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{:code => 1 + 2}
+ = "Holy cow " + |
+ "multiline " + |
+ "tags! " + |
+ "A pipe (|) even!" |
+ = [1, 2, 3].collect { |n| "PipesIgnored|" }.join
+ = [1, 2, 3].collect { |n| |
+ n.to_s |
+ }.join("|") |
+ - bar = 17
+ %div.silent{:foo => bar}
+ - 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"
+ = "foo".each_line do |line|
+ - nil
+ .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"

0 comments on commit cf586b6

Please sign in to comment.