Created
January 30, 2012 22:37
-
-
Save louismullie/1707242 to your computer and use it in GitHub Desktop.
Benchmark: Array.include? vs. Hash.include?
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 'benchmark' | |
array = (1..1_000_000).to_a | |
hash = Hash[array.map {|x| [x, nil]}] | |
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) } } | |
end | |
# user system total real | |
# Array.include? 46.190000 0.160000 46.350000 ( 46.593477) | |
# Hash.include? 0.000000 0.000000 0.000000 ( 0.000523) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment