Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created August 30, 2010 16:53
Show Gist options
  • Save metaskills/557674 to your computer and use it in GitHub Desktop.
Save metaskills/557674 to your computer and use it in GitHub Desktop.
require 'bench_press'
extend BenchPress
author 'Ken Collins'
summary 'Object class inspection vs duck typing.'
reps 100_000
module Foo
class Bar
def to_foo
end
end
class Batz
end
end
@bar = Foo::Bar.new
@batz = Foo::Batz.new
measure "Object#is_a?" do
@bar.is_a?(Foo::Bar)
@batz.is_a?(Foo::Bar)
end
measure "Object#respond_to?" do
@bar.respond_to?(:to_foo)
@batz.respond_to?(:to_foo)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment