pub struct Benchmark { /* private fields */ }Expand description
A single benchmark run.
Collects per-iteration duration samples. Call Benchmark::finish
to produce a BenchmarkResult.
§Example
use dev_bench::Benchmark;
let mut b = Benchmark::new("noop");
for _ in 0..10 {
b.iter(|| std::hint::black_box(42));
}
let r = b.finish();
assert_eq!(r.samples.len(), 10);Implementations§
Source§impl Benchmark
impl Benchmark
Sourcepub fn iter<F, R>(&mut self, f: F) -> Rwhere
F: FnOnce() -> R,
pub fn iter<F, R>(&mut self, f: F) -> Rwhere
F: FnOnce() -> R,
Run one iteration of the benchmark, capturing the duration.
Each call records exactly one sample.
§Example
use dev_bench::Benchmark;
let mut b = Benchmark::new("noop");
b.iter(|| std::hint::black_box(1 + 1));
let r = b.finish();
assert_eq!(r.samples.len(), 1);Sourcepub fn iter_with_count<F>(&mut self, n: u64, f: F)where
F: FnMut(),
pub fn iter_with_count<F>(&mut self, n: u64, f: F)where
F: FnMut(),
Run a closure n times and record ONE sample for the entire batch.
Use for sub-microsecond operations where per-iteration timing
would be dominated by Instant::now() overhead. The reported
per-iteration mean is batch_duration / n.
§Example
use dev_bench::Benchmark;
let mut b = Benchmark::new("hot");
b.iter_with_count(1000, || {
std::hint::black_box(40 + 2);
});
let r = b.finish();
assert_eq!(r.samples.len(), 1);
assert_eq!(r.iterations_recorded, 1000);Sourcepub fn finish(self) -> BenchmarkResult
pub fn finish(self) -> BenchmarkResult
Finalize the benchmark and produce a BenchmarkResult.
Auto Trait Implementations§
impl Freeze for Benchmark
impl RefUnwindSafe for Benchmark
impl Send for Benchmark
impl Sync for Benchmark
impl Unpin for Benchmark
impl UnsafeUnpin for Benchmark
impl UnwindSafe for Benchmark
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more