Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Hash vs. Array vs. Set
require 'benchmark'
require 'set'
Document =,:a,:b,:c)
documents_a = []
documents_h = {}
documents_s =
1.upto(10_000) do |n|
d =
documents_a << d
documents_h[] = d
documents_s << d
searchlist ={ rand(10_000)+1 } do |x|'array') {searchlist.each{|el| documents_a.any?{|d| == el}} }'hash') {searchlist.each{|el| documents_h.has_key?(el)} }'set') {searchlist.each{|el| documents_s.include?(el)} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.