Created
October 8, 2010 17:48
-
-
Save luislavena/617193 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
require 'slim' | |
require 'erubis' | |
#gem 'haml', '3.0.21' | |
gem 'haml', '3.1.0.alpha.14' | |
require 'haml' | |
slim = <<-SLIM | |
! doctype html | |
html | |
head | |
title Test | |
body | |
h1 simple markup | |
div#content | |
- unless items.empty? | |
ol | |
- for item in items do | |
li | |
= item | |
- else | |
p No items | |
SLIM | |
erb = <<-ERB | |
<!doctype html> | |
<html> | |
<head> | |
<title>Test</title> | |
</head> | |
<body> | |
<h1>simple markup</h1> | |
<div id="content"> | |
<% unless items.empty? %> | |
<% for item in items do %> | |
<li><%= item %></li> | |
<% end %> | |
<% else %> | |
<p>No items</p> | |
<% end %> | |
</div> | |
</body> | |
</html> | |
ERB | |
haml= <<-HAML | |
!!! html | |
%html | |
%head | |
%title Test | |
%body | |
%h1 simple markup | |
%div#content | |
- unless items.empty? | |
- for item in items do | |
%li= item | |
- else | |
%p No items | |
HAML | |
class Foo | |
attr_reader :items | |
def initialize | |
@items = [1, 2, 3, 4, 5] | |
end | |
end | |
foo = Foo.new | |
n = 10_000 | |
Benchmark.bmbm do |bench| | |
bench.report('empty loop') { for i in 0..n; end } | |
# compute template every time | |
bench.report('erubis') { for i in 0..n; Erubis::Eruby.new(erb).result(:items => foo.items); end } | |
bench.report('slim') { for i in 0..n; Slim::Engine.new(slim).render(foo); end } | |
bench.report("haml #{Haml::VERSION}") { for i in 0..n; Haml::Engine.new(haml, :format => :html5).render(foo); end } | |
bench.report("haml (ugly) #{Haml::VERSION}") { for i in 0..n; Haml::Engine.new(haml, :format => :html5, :ugly => true).render(foo); end } | |
# cache compiled template | |
bench.report('erubis (cache)') { t = Erubis::Eruby.new(erb); for i in 0..n; t.result(:items => foo.items); end } | |
bench.report('slim (cache)') { t = Slim::Engine.new(slim); for i in 0..n; t.render(foo); end } | |
bench.report("haml #{Haml::VERSION} (cached)") { t = Haml::Engine.new(haml, :format => :html5); for i in 0..n; t.render(foo); end } | |
bench.report("haml (ugly) #{Haml::VERSION} (cached)") { t = Haml::Engine.new(haml, :format => :html5, :ugly => true); for i in 0..n; t.render(foo); end } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rehearsal -------------------------------------------------------------------------------- | |
empty loop 0.000000 0.000000 0.000000 ( 0.001000) | |
erubis 2.262000 0.000000 2.262000 ( 2.286131) | |
slim 3.806000 0.000000 3.806000 ( 3.805217) | |
haml 3.0.21 (Classy Cassidy) 17.207000 0.000000 17.207000 ( 17.221985) | |
haml (ugly) 3.0.21 (Classy Cassidy) 16.443000 0.000000 16.443000 ( 16.478943) | |
erubis (cache) 1.014000 0.000000 1.014000 ( 1.007058) | |
slim (cache) 0.733000 0.000000 0.733000 ( 0.739042) | |
haml 3.0.21 (Classy Cassidy) (cached) 1.638000 0.000000 1.638000 ( 1.632093) | |
haml (ugly) 3.0.21 (Classy Cassidy) (cached) 1.342000 0.000000 1.342000 ( 1.334077) | |
---------------------------------------------------------------------- total: 44.445000sec | |
user system total real | |
empty loop 0.000000 0.000000 0.000000 ( 0.001000) | |
erubis 2.277000 0.000000 2.277000 ( 2.299131) | |
slim 3.791000 0.000000 3.791000 ( 3.777216) | |
haml 3.0.21 (Classy Cassidy) 17.113000 0.000000 17.113000 ( 17.141980) | |
haml (ugly) 3.0.21 (Classy Cassidy) 16.458000 0.000000 16.458000 ( 16.454941) | |
erubis (cache) 0.999000 0.000000 0.999000 ( 1.006057) | |
slim (cache) 0.733000 0.000000 0.733000 ( 0.729042) | |
haml 3.0.21 (Classy Cassidy) (cached) 1.654000 0.000000 1.654000 ( 1.644094) | |
haml (ugly) 3.0.21 (Classy Cassidy) (cached) 1.326000 0.000000 1.326000 ( 1.338077) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rehearsal --------------------------------------------------------------------------------------- | |
empty loop 0.000000 0.000000 0.000000 ( 0.001000) | |
erubis 2.277000 0.000000 2.277000 ( 2.285131) | |
slim 3.775000 0.000000 3.775000 ( 3.771215) | |
haml 3.1.0.alpha.14 (Bleeding Edge) 17.036000 0.000000 17.036000 ( 17.057976) | |
haml (ugly) 3.1.0.alpha.14 (Bleeding Edge) 16.349000 0.000000 16.349000 ( 16.415939) | |
erubis (cache) 0.998000 0.000000 0.998000 ( 1.009058) | |
slim (cache) 0.733000 0.000000 0.733000 ( 0.740042) | |
haml 3.1.0.alpha.14 (Bleeding Edge) (cached) 1.607000 0.000000 1.607000 ( 1.612092) | |
haml (ugly) 3.1.0.alpha.14 (Bleeding Edge) (cached) 1.342000 0.000000 1.342000 ( 1.332076) | |
----------------------------------------------------------------------------- total: 44.117000sec | |
user system total real | |
empty loop 0.000000 0.000000 0.000000 ( 0.001000) | |
erubis 2.262000 0.000000 2.262000 ( 2.264129) | |
slim 3.729000 0.000000 3.729000 ( 3.746215) | |
haml 3.1.0.alpha.14 (Bleeding Edge) 17.051000 0.000000 17.051000 ( 17.067976) | |
haml (ugly) 3.1.0.alpha.14 (Bleeding Edge) 16.473000 0.000000 16.473000 ( 16.503944) | |
erubis (cache) 1.045000 0.000000 1.045000 ( 1.033059) | |
slim (cache) 0.718000 0.000000 0.718000 ( 0.738042) | |
haml 3.1.0.alpha.14 (Bleeding Edge) (cached) 1.794000 0.000000 1.794000 ( 1.810104) | |
haml (ugly) 3.1.0.alpha.14 (Bleeding Edge) (cached) 1.342000 0.000000 1.342000 ( 1.327076) |
Yes, I understand that. See my updated gist with the comments.
Also in this gist I bench 0.5 release, not 0.6 beta.
Cool. Thanks for putting all of these together.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Slim escapes html by default, so to be a functional comparison you'll need to use == in Slim to bypass the escape call.