LinuxCommandLibrary

cargo-bench

Compile and run benchmarks for a Rust project

TLDR

Run all benchmarks

$ cargo bench
copy
Run specific benchmark
$ cargo bench [bench_name]
copy
Compile without running
$ cargo bench --no-run
copy
Run all benchmarks in workspace
$ cargo bench --workspace
copy
Continue on failure
$ cargo bench --no-fail-fast
copy
Benchmark specific package
$ cargo bench -p [package]
copy
Benchmark all targets
$ cargo bench --all-targets
copy

SYNOPSIS

cargo bench [options] [benchname] [-- bench-options]

DESCRIPTION

cargo bench compiles and executes benchmarks. By default, it uses the bench profile with optimizations enabled and debugging disabled. Benchmarks are run serially in a single thread.
The working directory is set to the package root directory.

PARAMETERS

--no-run

Compile but don't run benchmarks
--no-fail-fast
Run all benchmarks regardless of failures
--all-targets
Benchmark lib, bins, tests, benches, examples
--workspace
Benchmark all workspace members
-p, --package spec
Benchmark only specified packages
--lib
Benchmark library
--bins
Benchmark all binaries
--benches
Benchmark all bench targets
--profile name
Build with specific profile
-j, --jobs n
Number of parallel build jobs
--features features
Enable specified features
--all-features
Enable all features
--no-default-features
Disable default features

BENCHMARKING FRAMEWORKS

libtest bench

Built-in, requires nightly Rust
Criterion
Popular stable harness, feature-rich
Iai
Instruction-counting benchmarks

CAVEATS

Built-in benchmarking requires nightly Rust. The --jobs flag affects build parallelism, not benchmark execution. Consider Criterion for stable Rust.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community