-
-
Save brynary/65516 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
#!/usr/bin/env ruby | |
require 'benchmark' | |
require 'rubygems' | |
require 'markaby' | |
require 'tagz' | |
require 'builder' | |
require 'nokogiri' | |
max = (ARGV.shift || 10_000).to_i | |
def do_nothing | |
# do nothing | |
end | |
require 'haml' | |
require 'erubis' | |
@obj = Object.new | |
eruby = <<-EOF | |
<html> | |
<head> | |
<title>happy title</title> | |
</head> | |
<body> | |
<h1>happy heading</h1> | |
<a href='<%= 'url' %>'>a link</a> | |
</body> | |
</html> | |
EOF | |
Erubis::Eruby.new(eruby).def_method(@obj, :erubis) | |
def do_erubis | |
@obj.erubis | |
end | |
haml = <<-EOF | |
%html | |
%head | |
%title "happy title" | |
%body | |
%h1 "happy heading" | |
%a{:href => "url"} "a link" | |
EOF | |
Haml::Engine.new(haml, :ugly => true).def_method(@obj, :haml) | |
def do_haml | |
@obj.haml | |
end | |
def do_tagz | |
Tagz { | |
html_ { | |
head_ { | |
title_ "happy title" | |
} | |
body_ { | |
h1_ "happy heading" | |
a_ "a link", :href => "url" | |
} | |
} | |
} | |
end | |
def do_builder | |
Builder::XmlMarkup.new.html { |xm| | |
xm.head { | |
xm.title "happy title" | |
} | |
xm.body { | |
xm.h1 "happy heading" | |
xm.a "a link", :href => "url" | |
} | |
} | |
end | |
def do_markaby | |
mab = Markaby::Builder.new :output_meta_tag => false | |
mab.html { | |
head { | |
title "happy title" | |
} | |
body { | |
h1 "happy heading" | |
a "a link", :href => "url" | |
} | |
}.to_s | |
end | |
def do_nokogiri | |
html = Nokogiri do | |
html do | |
head do | |
title "happy title" | |
end | |
body do | |
h1 "happy heading" | |
a "a link", :href => "url" | |
end | |
end | |
end | |
html.to_s | |
end | |
puts "# of iterations = #{max}" | |
Benchmark::bm(20) do |x| | |
x.report("null_time") do | |
for i in 0..max do | |
do_nothing | |
end | |
end | |
x.report("tagz") do | |
for i in 0..max do | |
do_tagz | |
end | |
end | |
x.report("haml") do | |
for i in 0..max do | |
do_haml | |
end | |
end | |
x.report("erubis") do | |
for i in 0..max do | |
do_erubis | |
end | |
end | |
x.report("markaby") do | |
for i in 0..max do | |
do_markaby | |
end | |
end | |
x.report("builder") do | |
for i in 0..max do | |
do_builder | |
end | |
end | |
x.report("nokogiri") do | |
for i in 0..max do | |
do_nokogiri | |
end | |
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
# of iterations = 10000 | |
user system total real | |
null_time 0.000000 0.000000 0.000000 ( 0.002579) | |
tagz 2.040000 0.030000 2.070000 ( 2.093773) | |
haml 0.150000 0.000000 0.150000 ( 0.150317) | |
erubis 0.020000 0.000000 0.020000 ( 0.019690) | |
markaby 8.040000 0.050000 8.090000 ( 8.336001) | |
builder 1.790000 0.010000 1.800000 ( 1.811590) | |
nokogiri 1.340000 0.010000 1.350000 ( 1.363197) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment