Function bench_diff_x

Source
pub fn bench_diff_x(
    unit: LatencyUnit,
    f1: impl FnMut(),
    f2: impl FnMut(),
    exec_count: usize,
    warmup_status: impl FnMut(usize, u64, u64),
    pre_exec: impl FnOnce(),
    exec_status: impl FnMut(usize),
) -> DiffOut
Expand description

Compares latencies for two closures f1 and f2 and optionally outputs information about the benchmark and its execution status.

This function repeatedly executes duos of pairs (f1, f2), (f2, f1) and collects the resulting latency data in a DiffOut object. Prior to data collection, the benchmark is “warmed-up” by executing the duos of pairs for get_warmup_millis milliseconds.

Arguments:

  • unit - the unit used for data collection.
  • f1 - first target for comparison.
  • f2 - second target for comparison.
  • exec_count - number of executions (sample size) for each function.
  • warmup_status - is invoked every so often during warm-up and can be used to output the warm-up status, e.g., how much warm-up time has elapsed and the target warm-up time. The first argument is the warm-up execution iteration, the second is the elapsed warm-up time, and the third is the target warm-up time. (See the source code of bench_diff_with_status for an example.)
  • pre_exec - is invoked once at the beginning of data collection, after warm-up. It can be used, for example, to output a preamble to the execution status (see exec_status below).
  • exec_status - is invoked after the execution of each duo and can be used to output on the execution status, e.g., how many observations have been collected for the pair of functions versus exec_count. Its argument is the current number of executions performed. (See the source code of bench_diff_with_status for an example.)