Class: Holidays::Definition::Repository::ProcResultCache

Inherits:
Object
  • Object
show all
Defined in:
lib/holidays/definition/repository/proc_result_cache.rb

Overview

Benchmarks

Lookup Easter Sunday, with caching, by number of iterations:

user     system      total        real

0001 0.000000 0.000000 0.000000 ( 0.000000) 0010 0.000000 0.000000 0.000000 ( 0.000000) 0100 0.078000 0.000000 0.078000 ( 0.078000) 1000 0.641000 0.000000 0.641000 ( 0.641000) 5000 3.172000 0.015000 3.187000 ( 3.219000)

Lookup Easter Sunday, without caching, by number of iterations:

user     system      total        real

0001 0.000000 0.000000 0.000000 ( 0.000000) 0010 0.016000 0.000000 0.016000 ( 0.016000) 0100 0.125000 0.000000 0.125000 ( 0.125000) 1000 1.234000 0.000000 1.234000 ( 1.234000) 5000 6.094000 0.031000 6.125000 ( 6.141000)

Instance Method Summary collapse

Constructor Details

#initializeProcResultCache

Returns a new instance of ProcResultCache.



24
25
26
# File 'lib/holidays/definition/repository/proc_result_cache.rb', line 24

def initialize
  @proc_cache = {}
end

Instance Method Details

#lookup(function, *function_arguments) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/holidays/definition/repository/proc_result_cache.rb', line 28

def lookup(function, *function_arguments)
  validate!(function, function_arguments)

  proc_key = build_proc_key(function, function_arguments)
  @proc_cache[proc_key] = function.call(*function_arguments) unless @proc_cache[proc_key]
  @proc_cache[proc_key]
end