JuliaActuary / MortalityTables.jl

Easily Reference and use Actuarial Mortality Tables
https://juliaactuary.github.io/MortalityTables.jl/stable
Other
28 stars 10 forks source link

Faster table loading / caching #121

Closed alecloudenback closed 2 years ago

alecloudenback commented 2 years ago

Memoize table build so that subsequent calls are much faster:

Before:

julia> @benchmark MortalityTables.table("1980 CSO Basic Table – Male, ANB")
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min … max):  256.458 μs …  20.328 ms  ┊ GC (min … max): 0.00% … 42.11%
 Time  (median):     268.041 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   339.263 μs ± 982.478 μs  ┊ GC (mean ± σ):  7.75% ±  2.62%

      ▆█▇▄▂                                                      
  ▁▂▃███████▆▆▆▅▄▃▃▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
  256 μs           Histogram: frequency by time          350 μs <

 Memory estimate: 213.61 KiB, allocs estimate: 3441.

after:

 julia> @benchmark MortalityTables.table("1980 CSO Basic Table – Male, ANB")
BenchmarkTools.Trial: 10000 samples with 5 evaluations.
 Range (min … max):  6.358 μs … 478.325 μs  ┊ GC (min … max): 0.00% … 97.82%
 Time  (median):     6.608 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   7.047 μs ±  12.119 μs  ┊ GC (mean ± σ):  4.78% ±  2.75%

      ▆█▇▇▄▂                                                   
  ▁▂▄███████▇▆▄▄▄▃▃▃▂▂▂▂▂▂▂▁▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
  6.36 μs         Histogram: frequency by time         8.3 μs <

 Memory estimate: 7.28 KiB, allocs estimate: 64.
codecov[bot] commented 2 years ago

Codecov Report

Merging #121 (08a3ee6) into master (171fa69) will decrease coverage by 1.00%. The diff coverage is 95.83%.

@@            Coverage Diff             @@
##           master     #121      +/-   ##
==========================================
- Coverage   90.16%   89.15%   -1.01%     
==========================================
  Files           9        9              
  Lines         366      369       +3     
==========================================
- Hits          330      329       -1     
- Misses         36       40       +4     
Impacted Files Coverage Δ
src/get_SOA_table.jl 66.66% <80.00%> (-33.34%) :arrow_down:
src/MortalityTable.jl 96.55% <100.00%> (-1.64%) :arrow_down:

:mega: Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

alecloudenback commented 2 years ago

nevermind, accidentally pushed to master the change