Skip to content

Instantly share code, notes, and snippets.

@nirix
Created April 25, 2012 22:53
Show Gist options
  • Save nirix/2494111 to your computer and use it in GitHub Desktop.
Save nirix/2494111 to your computer and use it in GitHub Desktop.
ERB vs Erubis
require 'erb'
require 'erubis'
require 'benchmark'
@hey = "Herro prease"
@lols = [
'12', '34', '56', '78', '90',
'ab', 'cd', 'ef', 'gh', 'ij',
'kl', 'mn', 'op', 'qr', 'st',
'uv', 'wx', 'yz',
'test', 'tester', 'testing',
'php', 'is', 'amaingly', 'shit',
'ruby', 'is', 'the', 'awesomeness',
]
Benchmark.bm(100) do |x|
x.report("ERB") do
50.times do
ERB.new(File.read('./test.erb'), 0, '<>')
end
end
x.report("Erubis") do
50.times do
Erubis::Eruby.new(File.read('./test.erb'))
end
end
end
user system total real
ERB 0.020000 0.000000 0.020000 ( 0.026359)
Erubis 0.010000 0.000000 0.010000 ( 0.006568)
<html>
<head>
<title>Test</title>
</head>
<body>
<header>
<h1>Test</h1>
</header>
<section>
<div class="msg">
<%= @hey %>
</div>
<div class="lols">
<% @lols.each do |lol| %>
<div><%= lol %></div>
<% end %>
</div>
</section>
<footer>
Test
</footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment