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. For Laplace approximation the time only include the time
for drawing the approximate sample and does not include the time
taken to run the $optimize()
method.
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] 1.020517
#>
#> $chains
#> chain_id warmup sampling total
#> 1 1 0.030 0.101 0.131
#> 2 2 0.027 0.095 0.122
#> 3 3 0.031 0.099 0.130
#> 4 4 0.026 0.112 0.138
#>
fit_vb <- cmdstanr_example("logistic", method = "variational")
fit_vb$time()
#> $total
#> [1] 0.1371388
#>
fit_mle <- cmdstanr_example("logistic", method = "optimize", jacobian = TRUE)
fit_mle$time()
#> $total
#> [1] 0.1316919
#>
# use fit_mle to draw samples from laplace approximation
fit_laplace <- cmdstanr_example("logistic", method = "laplace", mode = fit_mle)
fit_laplace$time() # just time for drawing sample not for running optimize
#> $total
#> [1] 0.131767
#>
fit_laplace$time()$total + fit_mle$time()$total # total time
#> [1] 0.263459
# }