Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'benchmark'
hash = { a: 'a', b: 'b', c: 'c', d: 'd' }.freeze
keys = [:a, :b].freeze
n = 500_000
Benchmark.bm do |x|
x.report do
n.times do
hash1 = hash.dup
hash1.delete_if {|key, _| keys.include?(key)}
end
end
x.report do
n.times do
hash2 = hash.dup
keys.each do |key|
hash2.delete(key)
end
end
end
end
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.