Created
November 16, 2014 22:30
-
-
Save allcentury/804efd03a9d31abeb266 to your computer and use it in GitHub Desktop.
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 'set' | |
require 'benchmark' | |
def reject_this_set(list, ids) | |
order_set = Set.new | |
ids.each { |i| order_set << i } | |
list.reject { |val| order_set.include?(val[:order_id]) } | |
end | |
def reject_this(list, ids) | |
list.reject { |val| ids.include?(val[:order_id]) } | |
end | |
fake_orders = [] | |
1_000_000.times do |i| | |
fake_orders << { order_id: i.to_s, name: "John #{i}" } | |
end | |
fake_order_ids = (1..100_000).to_a.sample(5_000) | |
Benchmark.bm do |bm| | |
bm.report { reject_this(fake_orders, fake_order_ids) } | |
bm.report { reject_this(fake_orders, fake_order_ids) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment