FastSurvival is designed for repeated evaluation inside large simulation loops. This vignette shows how to benchmark each function against its standard counterpart and reports representative results. The benchmark code is shown but not executed when the vignette is built, because timing many microbenchmark replicates would exceed the build-time limits. To reproduce the numbers, run the code blocks interactively.
The reported figures are median times from microbenchmark replicates on a single desktop machine. Absolute timings depend on hardware, sample size, and event rate, so the ratios matter more than the raw values.
The key to the speed gain is that the analysis functions accept pre-sorted vectors. Inside a simulation loop the data are sorted once and reused, so the sort cost is paid a single time rather than on every call. We build a single phase-3-sized dataset for the benchmarks.
The Kalbfleisch-Prentice average hazard ratio is benchmarked against
ahrKM() from the AHR package, the reference implementation
used by Dormuth et al. (2024). Because AHR has been archived on CRAN,
this benchmark is shown as a static block rather than a live chunk, so
the vignette carries no undeclared dependency. Install AHR with
remotes::install_github("cran/AHR") and run the block to
reproduce it.
The table below summarizes representative median timings on a typical
phase-3 dataset (n = 600, event rate 80%) with
presorted = TRUE. The exact values will differ on your
machine, but the order of magnitude of the speedup is stable.
| Function | Replaces | Approximate speed gain |
|---|---|---|
survfit_fast() |
survfit() + summary() at one time
point |
~70x |
survdiff_fast() |
survdiff() |
~50x |
coxph_fast() |
coxph() (point estimate + Wald CI) |
~50x |
rmst_fast() |
survRM2::rmst2() |
~60x |
survdiff_fast(weight = "fh") |
nph::logrank.test() |
~500x |
ahr_fast() |
AHR::ahrKM() |
~130x |
Each function avoids the overhead that the standard implementations incur on every call. The standard functions parse a formula, build an S3 model object, and construct intermediate vectors before producing the result, which is appropriate for interactive use but wasteful when the same operation is repeated thousands of times. The FastSurvival functions take plain vectors, do the core computation in a single C++ pass over the data, and return a lightweight numeric vector. When the input is already sorted the sort cost is avoided entirely. In a simulation loop these savings accumulate across every iteration.
Kalbfleisch, J. D., & Prentice, R. L. (1981). Estimation of the average hazard ratio. Biometrika, 68(1), 105-112.
Dormuth, I., Pauly, M., Rauch, G., & Herrmann, C. (2024). Sample size calculation under nonproportional hazards using average hazard ratios. Biometrical Journal, 66(6), e202300271.