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()

Value

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".

Examples

# \dontrun{
fit_mcmc <- cmdstanr_example("logistic", method = "sample")
fit_mcmc$time()
#> $total
#> [1] 0.554847
#> 
#> $chains
#>   chain_id warmup sampling total
#> 1        1  0.023    0.071 0.094
#> 2        2  0.022    0.066 0.088
#> 3        3  0.023    0.071 0.094
#> 4        4  0.023    0.071 0.094
#> 

fit_vb <- cmdstanr_example("logistic", method = "variational")
fit_vb$time()
#> $total
#> [1] 0.1302531
#> 

fit_mle <- cmdstanr_example("logistic", method = "optimize", jacobian = TRUE)
fit_mle$time()
#> $total
#> [1] 0.1320548
#> 

# 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.126792
#> 
fit_laplace$time()$total + fit_mle$time()$total # total time
#> [1] 0.2588468
# }