Cargo bench
cargo bench is a Cargo command that builds and runs a Rust package's benchmark targets.
Refactoring to Rust
cargo bench is a Cargo command that builds and runs a package's benchmarks.
- How it is used
- Runs package benchmarks and presents measured execution-time estimates.
- How deep it goes
- Explains invocation and Criterion output, while deferring benchmark implementation details to separate source files.
- Examples
- Uses u8 and u128 arithmetic benchmarks and compares pure Python with a Rust extension library.
- What you can do after
- Operate/configure it to run benchmarks and interpret Criterion's timing intervals and sample estimates.
Idiomatic Rust
cargo bench is a Cargo command that compiles benchmarks in release mode and executes them.
- How it is used
- Runs benchmarks rather than tests to compare performance across collection operations.
- How deep it goes
- Shows #[bench] functions using Bencher and sample timings, while leaving the full benchmark suite elsewhere.
- Examples
- Benchmarks appending one million elements and finding or removing values in million-element collections.
- What you can do after
- Evaluate collection performance by running benchmarks and comparing measured timings, while allowing for machine-to-machine variation.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

