Created
January 27, 2015 13:42
-
-
Save eagletmt/5f98b900ab844374208a 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
#!/usr/bin/env ruby | |
require 'benchmark/ips' | |
require 'slim' | |
t1 = 1000.times.map do |i| | |
"span*{foo: #{i}}" | |
end.join("\n") | |
t2 = 1000.times.map do |i| | |
"span foo=#{i}" | |
end.join("\n") | |
t3 = 1000.times.map do |i| | |
"span foo='#{i}'" | |
end.join("\n") | |
obj = Object.new | |
obj.instance_eval("def t1; #{Slim::Engine.new.call(t1)}; end") | |
obj.instance_eval("def t2; #{Slim::Engine.new.call(t2)}; end") | |
obj.instance_eval("def t3; #{Slim::Engine.new.call(t3)}; end") | |
puts "Slim::VERSION #{Slim::VERSION}" | |
Benchmark.ips do |x| | |
x.report('t1') { obj.t1 } | |
x.report('t2') { obj.t2 } | |
x.report('t3') { obj.t3 } | |
x.compare! | |
end | |
__END__ | |
Slim::VERSION 3.0.1 | |
Calculating ------------------------------------- | |
t1 10.000 i/100ms | |
t2 69.000 i/100ms | |
t3 12.232k i/100ms | |
------------------------------------------------- | |
t1 100.026 (± 2.0%) i/s - 500.000 | |
t2 691.137 (± 3.2%) i/s - 3.519k | |
t3 155.544k (± 9.7%) i/s - 782.848k | |
Comparison: | |
t3: 155543.8 i/s | |
t2: 691.1 i/s - 225.05x slower | |
t1: 100.0 i/s - 1555.04x slower | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment