Skip to content

Instantly share code, notes, and snippets.

@cheald
Created October 17, 2012 20:29
Show Gist options
  • Save cheald/3907949 to your computer and use it in GitHub Desktop.
Save cheald/3907949 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'benchmark'
require 'erubis'
class Context
def initialize
@items = {
"Headline 1" => %w[Link1 Link2 Link3 Link4 Link5 Link6 Link7],
"Headline 2" => %w[Link1 Link2 Link3 Link4 Link5 Link6 Link7],
"Headline 3" => %w[Link1 Link2 Link3 Link4 Link5 Link6 Link7],
"Headline 4" => %w[Link1 Link2 Link3 Link4 Link5 Link6 Link7]
}
end
end
context = Context.new
context_binding = context.instance_eval { binding }
@erb_code = open('erb_page.html.erb').read
TIMES = 10000
e = Erubis::FastEruby.new(@erb_code)
Benchmark.bm do |x|
x.report("Erubis") {
TIMES.times do
e.result(context_binding)
end
}
end
% ruby erubis.rb
user system total real
Erubis 1.140000 0.020000 1.160000 ( 1.170378)
8,547 req/sec single-threaded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment