Created
November 14, 2016 18:59
-
-
Save AnotherJoSmith/ffdb9dcedf4603f0117d6c99904f3aa5 to your computer and use it in GitHub Desktop.
This file contains 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 "holidays" | |
require "benchmark" | |
require "active_support/core_ext/numeric/time" | |
require "active_support/core_ext/date/acts_like" | |
rng = Random.new | |
dates = [] | |
n = 10000 | |
n.times do | |
dates << (Date.today + rng.rand(365).days) | |
end | |
puts 'Without cache' | |
puts Benchmark.measure { dates.each { |date| Holidays.on(date, :us, :observed)} } | |
puts 'With cache' | |
Holidays.cache_between(Time.now, Date.today + 365.days, :us, :ca, :gb, :ie, :observed) | |
puts Benchmark.measure { dates.each { |date| Holidays.on(date, :us, :observed)} } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment