Skip to content

Instantly share code, notes, and snippets.

@eagletmt
Created January 27, 2015 13:18
Show Gist options
  • Save eagletmt/4b0f6468b6458ef9cae6 to your computer and use it in GitHub Desktop.
Save eagletmt/4b0f6468b6458ef9cae6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'benchmark/ips'
require 'haml'
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")
t4 = 1000.times.map do |i|
"%span{:foo => '#{i}'}"
end.join("\n")
obj = Object.new
Haml::Engine.new(t1).def_method(obj, :t1)
Haml::Engine.new(t2).def_method(obj, :t2)
Haml::Engine.new(t3).def_method(obj, :t3)
Haml::Engine.new(t4).def_method(obj, :t4)
puts "Haml::VERSION #{Haml::VERSION}"
Benchmark.ips do |x|
x.report('t1') { obj.t1 }
x.report('t2') { obj.t2 }
x.report('t3') { obj.t3 }
x.report('t4') { obj.t4 }
x.compare!
end
__END__
Haml::VERSION 4.0.6
Calculating -------------------------------------
t1 5.000 i/100ms
t2 5.000 i/100ms
t3 5.000 i/100ms
t4 3.300k i/100ms
-------------------------------------------------
t1 56.953 (± 1.8%) i/s - 285.000
t2 57.075 (± 1.8%) i/s - 290.000
t3 56.769 (± 1.8%) i/s - 285.000
t4 40.728k (± 6.9%) i/s - 204.600k
Comparison:
t4: 40728.0 i/s
t2: 57.1 i/s - 713.59x slower
t1: 57.0 i/s - 715.11x slower
t3: 56.8 i/s - 717.43x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment