liveBook · Manning

Bencher

As explained in Refactoring to Rust

Bencher is the Criterion type that controls repeated execution of a benchmark iteration closure.

Bencher is Criterion’s mutable benchmark handle. Pass it to a benchmark helper, then call iter with a closure containing the operation to measure. section 6.5

Measuring an operation

c.bench_function("u8", |b| { b.iter(|| { black_box(3u8 + 4); }); }); The iter closure runs repeatedly while Criterion measures it. Passing the result to black_box prevents the compiler from optimizing away an unused computation. section 6.5

How Refactoring to Rust covers it

How deep it goes
Explains Bencher’s mutable input and iter’s repeated execution, looping, and measurement, but defers configuration details.
Examples
Uses u8 and u128 arithmetic benchmarks plus a Python-versus-Rust extension benchmark.
What it assumes
Assumes a Criterion benchmark function and teaches the Bencher-to-iter step directly.
What you can do after
Apply it via Criterion to place repeated work inside a measured benchmark iteration.
How it connects
Connects Criterion, benchmark functions, closures, and black_box.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Refactoring to Rust. The section links point to the parts of the book it draws on.