Created
December 12, 2008 23:15
-
-
Save dscataglini/35322 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 'rubygems' | |
require 'andand' | |
require 'benchmark' | |
include Benchmark | |
t = 1_000_000 | |
class A | |
attr_accessor :foo | |
end | |
class B | |
def bar | |
"bar" | |
end | |
end | |
a = A.new | |
a.foo = B.new | |
b = A.new | |
bm(30) do |x| | |
x.report("andand"){ t.times{ a.foo.andand.bar }} | |
x.report("if"){ t.times{ a.foo.bar if a.foo }} | |
x.report("andand with nil"){ t.times{ b.foo.andand.bar }} | |
x.report("if with nil"){ t.times{ b.foo.bar if b.foo }} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment