Created
August 17, 2010 17:26
-
-
Save careo/530973 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
require 'benchmark' | |
require 'erb' | |
require 'rubygems' | |
require 'erubis' | |
# generate templates | |
LINES = 1_000 | |
perline = "" | |
single = "" | |
single += "<%\n" | |
LINES.times do |i| | |
perline += "<% #{i} %>\n" | |
single += "#{i}\n" | |
end | |
single += "%>" | |
N = 1_000 | |
Benchmark.bm(17) do |x| | |
x.report("erb per-line") do | |
N.times { ERB.new(perline).result } | |
end | |
GC.start | |
x.report("erb single") do | |
N.times { ERB.new(single).result } | |
end | |
GC.start | |
x.report("erubis per-line") do | |
N.times { Erubis::Eruby.new(perline).result } | |
end | |
GC.start | |
x.report("erubis single") do | |
N.times { Erubis::Eruby.new(single).result } | |
end | |
GC.start | |
x.report("just eval") do | |
N.times do | |
LINES.times { |i| i } | |
end | |
end | |
GC.start | |
end | |
__END__ | |
The results on my system: | |
user system total real | |
erb per-line 23.340000 0.060000 23.400000 ( 23.749460) | |
erb single 1.440000 0.000000 1.440000 ( 1.463565) | |
erubis per-line 10.450000 0.060000 10.510000 ( 10.653146) | |
erubis single 1.440000 0.010000 1.450000 ( 1.461613) | |
just eval 0.160000 0.000000 0.160000 ( 0.162416) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment