inst/benchmarks/benchmark-access.R

library(lifecontingencies)
data(soa08Act)

# Development benchmark for mortality-table access patterns from the legacy suite.
f <- function(x) soa08Act@lx[which(soa08Act@x == x)]
g <- function(j) soa08Act@lx[soa08Act@x[j + 2]]

if (soa08Act@x[1] == 0) {
  stopifnot(all(g(1:10) == sapply(1:10, f)))
  nrep <- 1000
  rbind(
    lookup = system.time(replicate(nrep, sapply(0:139, f))),
    indexed = system.time(replicate(nrep, g(0:139)))
  )[, 1:3]
}

Try the lifecontingencies package in your browser

Any scripts or data that you put into this service are public.

lifecontingencies documentation built on Aug. 24, 2026, 1:07 a.m.