bench_diff 1.1.0

Reliably compare the latencies of two functions/closures.
Documentation
1
2
3
4
5
6
7
8
9
use std::time::{Duration, Instant};

/// Invokes `f` once and returns its latency.
#[inline(always)]
pub fn latency(f: impl FnOnce()) -> Duration {
    let start = Instant::now();
    f();
    Instant::now().duration_since(start)
}