Created
February 16, 2009 18:53
-
-
Save nex3/65305 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' | |
max = (ARGV.shift || 1_000_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 | |
x = do_tagz | |
y = do_markaby | |
z = do_builder | |
raise "bad!\n\n#{x}\n\n#{y}" unless x == y | |
raise "bad!\n\n#{x}\n\n#{z}" unless x == z | |
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 | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment