Created
August 25, 2019 07:19
-
-
Save evaneykelen/705f755a2449d40494b3e8bdb529f205 to your computer and use it in GitHub Desktop.
Array vs Set benchmark
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' | |
require 'set' | |
array = File.readlines('dutch.bin') # 10k lines | |
hash = Hash[*array] # 5k keys => 5k values | |
set = array.to_set # 10k entries | |
line = array[-1] # Last line | |
Benchmark.bmbm do |x| | |
x.report("Array.include?") { 10_000.times { array.include?(line)} } | |
x.report("Hash.include?") { 10_000.times { hash.include?(line)} } | |
x.report("Set.include?") { 10_000.times { set.include?(line)} } | |
end |
Author
evaneykelen
commented
Aug 25, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment