Skip to content

Instantly share code, notes, and snippets.

@vpereira
Created March 22, 2012 13:07
Show Gist options
  • Save vpereira/2158259 to your computer and use it in GitHub Desktop.
Save vpereira/2158259 to your computer and use it in GitHub Desktop.
map.include? x any.respond_to?
require 'ostruct'
require 'benchmark'
net_objs = []
class NetworkObject < OpenStruct
·
end
0.upto(1000) { |n| net_objs.push NetworkObject.new(:name=>"foo #{n}",:removed=>[true,false].sample) }·
Benchmark.bm do |x|
x.report { net_objs.map(&:removed?).include?(true) }
x.report { net_objs.any? { |o| o.respond_to?(:removed?) && o.removed? } }
end
[~] ruby bmark.rb
user system total real
0.010000 0.000000 0.010000 ( 0.001116)
0.000000 0.000000 0.000000 ( 0.000385)
[~]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment