Skip to content

Instantly share code, notes, and snippets.

@demental
Created October 29, 2012 11:04
Show Gist options
  • Save demental/3972970 to your computer and use it in GitHub Desktop.
Save demental/3972970 to your computer and use it in GitHub Desktop.
respond_to? VS kind_of?
def with_respond(object)
object.respond_to?(:first)
end
def with_array(object)
object.kind_of? Array
end
class Aclass
end
Bench.run [:with_respond, :with_array] do |meth|
send(meth, Aclass.new)
end
---
name: benchmarks/micro-benchmarks/ba_app_first_or_array.rb
parameters:
- with_respond
- with_array
ruby_ver: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.2]; -O3 -g3 -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=shorten-64-to-32 -Werror=implicit-function-declaration -fno-common -pipe; '--prefix=/Users/demental/.rvm/rubies/ruby-1.9.3-p194' '--enable-shared' '--disable-install-doc' '--with-libyaml' '--with-opt-dir=/Users/demental/.rvm/usr' '--with-gcc=clang';/Users/demental/.rvm/rubies/ruby-1.9.3-p194/bin
---
name: benchmarks/micro-benchmarks/ba_app_first_or_array.rb
parameter: with_respond
iterations: 5
max: 8.0e-06
min: 4.0e-06
median: 4.0e-06
mean: 5.199999999999999e-06
standard_deviation: 1.6e-06
times:
- 6.0e-06
- 4.0e-06
- 4.0e-06
- 8.0e-06
- 4.0e-06
memory_usages:
- 44294144
- 44302336
- 44335104
- 44347392
- 44359680
---
name: benchmarks/micro-benchmarks/ba_app_first_or_array.rb
parameter: with_array
iterations: 5
max: 7.0e-06
min: 4.0e-06
median: 4.0e-06
mean: 4.9999999999999996e-06
standard_deviation: 1.2649110640673519e-06
times:
- 7.0e-06
- 4.0e-06
- 4.0e-06
- 6.0e-06
- 4.0e-06
memory_usages:
- 44412928
- 44462080
- 44470272
- 44482560
- 44490752
---
name: benchmarks/micro-benchmarks/ba_app_first_or_array.rb
status: success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment