Runs run_case(n_cores) for each core count, records the elapsed wall-clock
time of each run, and reports the median and spread together with the
speed-up and efficiency relative to the first core count. This is the
timing experiment behind the tables in Chapters 3 to 5 and the advice in
Chapter 7: time the whole call, including cluster start-up, discard
warm-up runs, and summarize with the median.
Arguments
- run_case
A function of one argument,
n_cores, that runs the complete simulation and returns its result. Typically a thin wrapper aroundsim_template()with every other argument fixed.- cores
Integer vector of core counts to time.
- n_runs
Number of timed runs at each core count.
- warmup
Number of untimed runs at each core count before timing starts.
- verbose
Print progress to the console.
Value
A data frame with one row per core count and columns cores,
median, iqr, min, max (seconds), speedup (first-row median over
this row's median), and efficiency (speedup / cores). The individual
run times are attached as the "times" attribute, a list of numeric
vectors.
Examples
# \donttest{
run_pi <- function(n_cores) sim_template(pi_worker, 1234, 100, 20000, n_cores)
benchmark_cores(run_pi, cores = 1:2, n_runs = 2, warmup = 0)
#> Benchmarking 1 core(s)
#> Benchmarking 2 core(s)
#> cores median iqr min max speedup efficiency
#> 1 1 0.4145 0.0005 0.414 0.415 1.000000 1.0000000
#> 2 2 0.3805 0.0085 0.372 0.389 1.089356 0.5446781
# }