Created
November 10, 2017 15:59
-
-
Save k0kubun/774e59d94dccbd94e5fc3fa3cd2f6fd5 to your computer and use it in GitHub Desktop.
Intel 4.0GHz i7-4790K with 16GB memory under x86-64 Ubuntu 8 Cores
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
# based on ruby/benchmark/bm_erb_render.rb | |
require 'benchmark/ips' | |
require 'erb' | |
require 'erubi' | |
require 'erubis' | |
data = DATA.read | |
mod = Module.new | |
mod.instance_eval("def self.erb(title, content); #{ERB.new(data).src}; end", "(ERB)") | |
mod.instance_eval("def self.erubis(title, content); #{Erubi::Engine.new(data).src}; end", "(Erubi)") | |
mod.instance_eval("def self.erubi(title, content); #{Erubis::Eruby.new(data).src}; end", "(Erubis)") | |
title = "hello world!" | |
content = "hello world!\n" * 10 | |
Benchmark.ips do |x| | |
x.report("ERB #{RUBY_VERSION}") { mod.erb(title, content) } | |
x.report("Erubis #{Erubis::VERSION}") { mod.erubis(title, content) } | |
x.report("Erubi #{Erubi::VERSION}") { mod.erubi(title, content) } | |
x.compare! | |
end | |
__END__ | |
<html> | |
<head> <%= title %> </head> | |
<body> | |
<h1> <%= title %> </h1> | |
<p> | |
<%= content %> | |
</p> | |
</body> | |
</html> |
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
$ ruby -v | |
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux] | |
$ ruby bm_erb_render.rb | |
Warming up -------------------------------------- | |
ERB 2.4.2 58.845k i/100ms | |
Erubis 2.7.0 106.377k i/100ms | |
Erubi 1.7.0 106.149k i/100ms | |
Calculating ------------------------------------- | |
ERB 2.4.2 661.271k (± 2.8%) i/s - 3.354M in 5.076345s | |
Erubis 2.7.0 1.384M (± 1.5%) i/s - 7.021M in 5.072377s | |
Erubi 1.7.0 1.341M (± 3.4%) i/s - 6.794M in 5.073353s | |
Comparison: | |
Erubis 2.7.0: 1384473.9 i/s | |
Erubi 1.7.0: 1340689.1 i/s - same-ish: difference falls within error | |
ERB 2.4.2: 661271.4 i/s - 2.09x slower |
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
$ ruby -v | |
ruby 2.5.0preview1 (2017-10-10 trunk 60153) [x86_64-linux] | |
$ ruby bm_erb_render.rb | |
Warming up -------------------------------------- | |
ERB 2.5.0 121.481k i/100ms | |
Erubis 2.7.0 104.338k i/100ms | |
Erubi 1.7.0 101.689k i/100ms | |
Calculating ------------------------------------- | |
ERB 2.5.0 1.643M (± 2.3%) i/s - 8.261M in 5.029894s | |
Erubis 2.7.0 1.288M (± 4.5%) i/s - 6.469M in 5.031078s | |
Erubi 1.7.0 1.240M (± 2.4%) i/s - 6.203M in 5.005898s | |
Comparison: | |
ERB 2.5.0: 1643278.0 i/s | |
Erubis 2.7.0: 1288439.6 i/s - 1.28x slower | |
Erubi 1.7.0: 1239862.2 i/s - 1.33x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment