Created
May 17, 2010 22:06
-
-
Save wesmaldonado/404290 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/ruby -w | |
require 'benchmark' | |
require 'set' | |
array = (1..1_000_000).to_a | |
hash = {} | |
array.map {|x| hash[x] = nil} | |
a_set = array.to_set | |
Benchmark.bm(15) do |x| | |
x.report("Array.include?") { 1000.times { array.include?(500_000) } } | |
x.report("Hash.include?") { 1000.times { hash.include?(500_000) } } | |
x.report("Set.include?") { 1000.times { a_set.include?(500_000) } } | |
end | |
## user system total real | |
## Array.include? 38.730000 0.010000 38.740000 ( 38.853568) | |
## Hash.include? 0.000000 0.000000 0.000000 ( 0.000922) | |
## Set.include? 0.000000 0.000000 0.000000 ( 0.001652) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment