Skip to content

Instantly share code, notes, and snippets.

@myabc
Created June 14, 2014 10:42
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 myabc/bc58d5cb49c679fd561c to your computer and use it in GitHub Desktop.
Save myabc/bc58d5cb49c679fd561c to your computer and use it in GitHub Desktop.
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