Skip to content

Instantly share code, notes, and snippets.

@AnotherJoSmith
Created November 14, 2016 18:59
Show Gist options
  • Save AnotherJoSmith/ffdb9dcedf4603f0117d6c99904f3aa5 to your computer and use it in GitHub Desktop.
Save AnotherJoSmith/ffdb9dcedf4603f0117d6c99904f3aa5 to your computer and use it in GitHub Desktop.
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