Created
December 23, 2016 09:36
-
-
Save begin29/b98ef0ec70fb5424492a40eb57bc5316 to your computer and use it in GitHub Desktop.
simple benchmark 2 ruby methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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