-
-
Save eregon/f279901e3df450d7a1970b76b9653c71 to your computer and use it in GitHub Desktop.
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
require 'benchmark/ips' | |
# initialized | |
class A | |
def initialize | |
@c = @d = @e = @f = @g = @h = nil | |
end | |
def b | |
@c || @d || @e || @f || @g || @h | |
end | |
end | |
# not initialized | |
class B | |
def initialize | |
# nothing | |
end | |
def b | |
@c || @d || @e || @f || @g || @h | |
end | |
end | |
def a0; A.new.b; end | |
def b0; B.new.b; end | |
Benchmark.ips do |x| | |
x.iterations = 2 | |
x.report('initialized') { a0 } | |
x.report('uninitialized') { b0 } | |
x.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment