Created
April 20, 2011 13:04
-
-
Save judofyr/931279 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'tilt' | |
require 'erb' | |
require 'benchmark' | |
# http://twitter.com/tiodante/status/60685349868929024 | |
# | |
# "Sinatra doesn't make ERB slow, Tilt does (and for smaller templates). ERB in | |
# itself is fast if used properly." | |
# Testing with a small template: | |
tpl = "Hello <%= @world %>" | |
class Scope | |
def initialize(world) | |
@world = world | |
end | |
def b; binding; end | |
end | |
erb = ERB.new(tpl) | |
erb.def_method(Scope, :cached_erb) | |
tilt = Tilt::ERBTemplate.new { tpl } | |
N = 50_000 | |
scope = Scope.new("World") | |
Benchmark.bmbm do |x| | |
x.report("ERB") { N.times { erb.result(scope.b) } } | |
x.report("ERB (cached)") { N.times { scope.cached_erb } } | |
x.report("Tilt") { N.times { tilt.render(scope) } } | |
end | |
Author
judofyr
commented
Apr 20, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment