Skip to content

Instantly share code, notes, and snippets.

@TikiTDO
Created June 19, 2013 03:54
Show Gist options
  • Save TikiTDO/5811578 to your computer and use it in GitHub Desktop.
Save TikiTDO/5811578 to your computer and use it in GitHub Desktop.
class A
def normal
@a = nil
@a ||= 1
end
def other_
@b = nil
@b = 1 if !@b
end
end
require 'benchmark'
i = A.new
puts Benchmark.measure{1000000.times{i.normal}} # => 0.190000 0.000000 0.190000 ( 0.194127)
puts Benchmark.measure{1000000.times{i.other_}} # => 0.150000 0.000000 0.150000 ( 0.164706)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment