Created
March 22, 2012 13:07
-
-
Save vpereira/2158259 to your computer and use it in GitHub Desktop.
map.include? x any.respond_to?
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 '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