Skip to content

Instantly share code, notes, and snippets.

@begin29
Created December 23, 2016 09:36
Show Gist options
  • Save begin29/b98ef0ec70fb5424492a40eb57bc5316 to your computer and use it in GitHub Desktop.
Save begin29/b98ef0ec70fb5424492a40eb57bc5316 to your computer and use it in GitHub Desktop.
simple benchmark 2 ruby methods
require 'benchmark'
iterations = 100_000
Benchmark.bm(27) do |bm|
bm.report('finding in hash') do
iterations.times do
arr.find{|h| h['start_date'] == '2018'}
end
end
bm.report('detect in hash') do
iterations.times do
arr.detect{|h| h['start_date'] == '2018'}
end
end
bm.report('select in hash') do
iterations.times do
arr.select{|h| h['start_date'] == '2018'}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment