← 返回命令列表

Linux command

cargo-bench 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Run all benchmarks

cargo bench

Run benchmarks whose name contains a substring

cargo bench [bench_name]

Compile benchmarks without running

cargo bench --no-run

Run benchmarks across the whole workspace

cargo bench --workspace

Continue running on benchmark failure

cargo bench --no-fail-fast

Benchmark a specific package

cargo bench -p [package]

Benchmark a specific bench target

cargo bench --bench [bench_target]

Pass arguments through to the bench binary

cargo bench -- --save-baseline [name]

说明

cargo bench compiles and executes benchmark targets of the current package. By default, it uses the `bench` profile (optimizations on, debug info minimal) and runs benchmarks serially. Arguments after `--` are forwarded to the compiled benchmark binary, which is how Criterion and libtest options such as `--save-baseline` or `--test` are passed through.

参数

--no-run
Compile benchmarks but do not execute them.
--no-fail-fast
Run every benchmark even if earlier ones fail.
--all-targets
Benchmark all targets (equivalent to `--lib --bins --tests --benches --examples`).
--workspace
Benchmark all packages in the workspace.
--exclude _SPEC_
Exclude packages from a `--workspace` run.
-p, --package _SPEC_
Benchmark only the specified package(s).
--lib
Benchmark only the library target.
--bins
Benchmark all binary targets.
--bin _NAME_
Benchmark only the named binary.
--benches
Benchmark all `bench = true` targets.
--bench _NAME_
Benchmark only the named bench target.
--examples
Benchmark all example targets.
--profile _NAME_
Build with a specific profile (defaults to `bench`).
--target _TRIPLE_
Build for the given target triple.
-j, --jobs _N_
Number of parallel build jobs (affects compilation, not benchmark execution).
-F, --features _FEATURES_
Space- or comma-separated list of features to activate.
--all-features
Activate all features of every selected package.
--no-default-features
Do not activate the `default` feature.
--manifest-path _PATH_
Path to `Cargo.toml`.
--locked
Require `Cargo.lock` to remain unchanged.
--offline
Do not access the network.

FAQ

What is the cargo-bench command used for?

cargo bench compiles and executes benchmark targets of the current package. By default, it uses the `bench` profile (optimizations on, debug info minimal) and runs benchmarks serially. Arguments after `--` are forwarded to the compiled benchmark binary, which is how Criterion and libtest options such as `--save-baseline` or `--test` are passed through.

How do I run a basic cargo-bench example?

Run `cargo bench` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --no-run do in cargo-bench?

Compile benchmarks but do not execute them.