Skip to content

Instantly share code, notes, and snippets.

@sturgill
Created July 9, 2012 13: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 sturgill/3076655 to your computer and use it in GitHub Desktop.
Save sturgill/3076655 to your computer and use it in GitHub Desktop.
Benchmark execution time of & vs include? with hashes
first = []
second = []
5000.times { |i| first.push({ :integer => i, :string => "some string here: #{i}" }) }
300.times { |i| second.push({ :integer => i * 17, :string => "some string here: #{i * 17}" }) }
Benchmark.measure { first & second }
Benchmark.measure { first.select { |f| second.include? f } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment