Skip to content

Instantly share code, notes, and snippets.

@tizoc
Created April 2, 2011 19:13
Show Gist options
  • Save tizoc/899782 to your computer and use it in GitHub Desktop.
Save tizoc/899782 to your computer and use it in GitHub Desktop.
require "./late"
require "erb"
require "bench"
def purecode(context = {})
myfield = context[:myfield]
out = "The sum is "
out.concat (2+2).to_s
out.concat " Also substitute "
out.concat (myfield).to_s
out.concat " ok"
out
end
erb = ERB.new("The sum is <%=2+2%> Also substitute <%=myfield%> ok")
myfield = 10
benchmark "rehearsal" do
late("The sum is <%=2+2%> Also substitute <%#myfield%> ok", {:myfield => 10})
purecode({:myfield => 10})
erb.result
end
benchmark "late" do
late("The sum is <%=2+2%> Also substitute <%#myfield%> ok", {:myfield => 10})
end
benchmark "purecode" do
purecode({:myfield => 10})
end
benchmark "erb" do
erb.result
end
run 10000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment