Skip to content

Instantly share code, notes, and snippets.

@allcentury
Created November 16, 2014 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allcentury/804efd03a9d31abeb266 to your computer and use it in GitHub Desktop.
Save allcentury/804efd03a9d31abeb266 to your computer and use it in GitHub Desktop.
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