Created
June 19, 2013 03:54
-
-
Save TikiTDO/5811578 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
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