Report the run time in seconds. For MCMC additional information is provided about the run times of individual chains and the warmup and sampling phases.
time()
A list with elements
total
: (scalar) The total run time. For MCMC this may be different than
the sum of the chain run times if parallelization was used.
chains
: (data frame) For MCMC only, timing info for the individual
chains. The data frame has columns "chain_id"
, "warmup"
, "sampling"
,
and "total"
.
# \dontrun{
fit_mcmc <- cmdstanr_example("logistic", method = "sample")
fit_mcmc$time()
#> $total
#> [1] 0.553201
#>
#> $chains
#> chain_id warmup sampling total
#> 1 1 0.021 0.068 0.089
#> 2 2 0.022 0.070 0.092
#> 3 3 0.022 0.076 0.098
#> 4 4 0.023 0.071 0.094
#>
fit_mle <- cmdstanr_example("logistic", method = "optimize")
fit_mle$time()
#> $total
#> [1] 0.1247039
#>
fit_vb <- cmdstanr_example("logistic", method = "variational")
fit_vb$time()
#> $total
#> [1] 0.1268399
#>
# }