Is there any way to exact the sampling time for MCMC chains in rstan? For both the total time and the time cost for each chain? Thanks.
There is rstan::get_elapsed_time()
but not sure if that gives you time per chain.
1 Like
What I usually do is
time_start <- Sys.time()
nuts_fit_1 <- rstan::sampling(...)
time_end <- Sys.time()
duration_nuts1 <- time_end - time_start
# This will give you the overall time:
print(duration_nuts1)
time_run <- rstan::get_elapsed_time(nuts_fit_1)
# This will give you the CPU time for the warmup phase and the CPU time for the post-warmup phase per chain:
print(time_run)
# And this give you the CPU time per chain:
apply(time_run, 1, sum)
1 Like
Use print(get_elapsed_time(fit))
. From this vignette, final section:
print(get_elapsed_time(fit))
warmup sample
chain:1 0.036806 0.022088
chain:2 0.045345 0.032371
chain:3 0.033602 0.032454
chain:4 0.032642 0.032313
1 Like