| '\" t |
| .\" Title: cargo-bench |
| .\" Author: [see the "AUTHOR(S)" section] |
| .\" Generator: Asciidoctor 1.5.8 |
| .\" Date: 2018-12-23 |
| .\" Manual: \ \& |
| .\" Source: \ \& |
| .\" Language: English |
| .\" |
| .TH "CARGO\-BENCH" "1" "2018-12-23" "\ \&" "\ \&" |
| .ie \n(.g .ds Aq \(aq |
| .el .ds Aq ' |
| .ss \n[.ss] 0 |
| .nh |
| .ad l |
| .de URL |
| \fI\\$2\fP <\\$1>\\$3 |
| .. |
| .als MTO URL |
| .if \n[.g] \{\ |
| . mso www.tmac |
| . am URL |
| . ad l |
| . . |
| . am MTO |
| . ad l |
| . . |
| . LINKSTYLE blue R < > |
| .\} |
| .SH "NAME" |
| cargo\-bench \- Execute benchmarks of a package |
| .SH "SYNOPSIS" |
| .sp |
| \fBcargo bench [\fIOPTIONS\fP] [BENCHNAME] [\-\- \fIBENCH\-OPTIONS\fP]\fP |
| .SH "DESCRIPTION" |
| .sp |
| Compile and execute benchmarks. |
| .sp |
| The benchmark filtering argument \fBBENCHNAME\fP and all the arguments following |
| the two dashes (\fB\-\-\fP) are passed to the benchmark binaries and thus to |
| \fIlibtest\fP (rustc\(cqs built in unit\-test and micro\-benchmarking framework). If |
| you\(cqre passing arguments to both Cargo and the binary, the ones after \fB\-\-\fP go |
| to the binary, the ones before go to Cargo. For details about libtest\(cqs |
| arguments see the output of \fBcargo bench \(em \-\-help\fP. As an example, this will |
| run only the benchmark named \fBfoo\fP (and skip other similarly named benchmarks |
| like \fBfoobar\fP): |
| .sp |
| .if n .RS 4 |
| .nf |
| cargo bench \-\- foo \-\-exact |
| .fi |
| .if n .RE |
| .sp |
| Benchmarks are built with the \fB\-\-test\fP option to \fBrustc\fP which creates an |
| executable with a \fBmain\fP function that automatically runs all functions |
| annotated with the \fB#[bench]\fP attribute. Cargo passes the \fB\-\-bench\fP flag to |
| the test harness to tell it to run only benchmarks. |
| .sp |
| The libtest harness may be disabled by setting \fBharness = false\fP in the target |
| manifest settings, in which case your code will need to provide its own \fBmain\fP |
| function to handle running benchmarks. |
| .SH "OPTIONS" |
| .SS "Benchmark Options" |
| .sp |
| \fB\-\-no\-run\fP |
| .RS 4 |
| Compile, but don\(cqt run benchmarks. |
| .RE |
| .sp |
| \fB\-\-no\-fail\-fast\fP |
| .RS 4 |
| Run all benchmarks regardless of failure. Without this flag, Cargo will exit |
| after the first executable fails. The Rust test harness will run all |
| benchmarks within the executable to completion, this flag only applies to |
| the executable as a whole. |
| .RE |
| .SS "Package Selection" |
| .sp |
| By default, when no package selection options are given, the packages selected |
| depend on the current working directory. In the root of a virtual workspace, |
| all workspace members are selected (\fB\-\-all\fP is implied). Otherwise, only the |
| package in the current directory will be selected. The default packages may be |
| overridden with the \fBworkspace.default\-members\fP key in the root \fBCargo.toml\fP |
| manifest. |
| .sp |
| \fB\-p\fP \fISPEC\fP..., \fB\-\-package\fP \fISPEC\fP... |
| .RS 4 |
| Benchmark only the specified packages. See \fBcargo\-pkgid\fP(1) for the |
| SPEC format. This flag may be specified multiple times. |
| .RE |
| .sp |
| \fB\-\-all\fP |
| .RS 4 |
| Benchmark all members in the workspace. |
| .RE |
| .sp |
| \fB\-\-exclude\fP \fISPEC\fP... |
| .RS 4 |
| Exclude the specified packages. Must be used in conjunction with the |
| \fB\-\-all\fP flag. This flag may be specified multiple times. |
| .RE |
| .SS "Target Selection" |
| .sp |
| When no target selection options are given, \fBcargo bench\fP will build the |
| following targets of the selected packages: |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04'\(bu\h'+03'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP \(bu 2.3 |
| .\} |
| lib — used to link with binaries and benchmarks |
| .RE |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04'\(bu\h'+03'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP \(bu 2.3 |
| .\} |
| bins (only if benchmark targets are built and required features are |
| available) |
| .RE |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04'\(bu\h'+03'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP \(bu 2.3 |
| .\} |
| lib as a benchmark |
| .RE |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04'\(bu\h'+03'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP \(bu 2.3 |
| .\} |
| bins as benchmarks |
| .RE |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04'\(bu\h'+03'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP \(bu 2.3 |
| .\} |
| benchmark targets |
| .RE |
| .sp |
| The default behavior can be changed by setting the \fBbench\fP flag for the target |
| in the manifest settings. Setting examples to \fBbench = true\fP will build and |
| run the example as a benchmark. Setting targets to \fBbench = false\fP will stop |
| them from being benchmarked by default. Target selection options that take a |
| target by name ignore the \fBbench\fP flag and will always benchmark the given |
| target. |
| .sp |
| Passing target selection flags will benchmark only the |
| specified targets. |
| .sp |
| \fB\-\-lib\fP |
| .RS 4 |
| Benchmark the package\(cqs library. |
| .RE |
| .sp |
| \fB\-\-bin\fP \fINAME\fP... |
| .RS 4 |
| Benchmark the specified binary. This flag may be specified multiple times. |
| .RE |
| .sp |
| \fB\-\-bins\fP |
| .RS 4 |
| Benchmark all binary targets. |
| .RE |
| .sp |
| \fB\-\-example\fP \fINAME\fP... |
| .RS 4 |
| Benchmark the specified example. This flag may be specified multiple times. |
| .RE |
| .sp |
| \fB\-\-examples\fP |
| .RS 4 |
| Benchmark all example targets. |
| .RE |
| .sp |
| \fB\-\-test\fP \fINAME\fP... |
| .RS 4 |
| Benchmark the specified integration test. This flag may be specified multiple |
| times. |
| .RE |
| .sp |
| \fB\-\-tests\fP |
| .RS 4 |
| Benchmark all targets in test mode that have the \fBtest = true\fP manifest |
| flag set. By default this includes the library and binaries built as |
| unittests, and integration tests. Be aware that this will also build any |
| required dependencies, so the lib target may be built twice (once as a |
| unittest, and once as a dependency for binaries, integration tests, etc.). |
| Targets may be enabled or disabled by setting the \fBtest\fP flag in the |
| manifest settings for the target. |
| .RE |
| .sp |
| \fB\-\-bench\fP \fINAME\fP... |
| .RS 4 |
| Benchmark the specified benchmark. This flag may be specified multiple times. |
| .RE |
| .sp |
| \fB\-\-benches\fP |
| .RS 4 |
| Benchmark all targets in benchmark mode that have the \fBbench = true\fP |
| manifest flag set. By default this includes the library and binaries built |
| as benchmarks, and bench targets. Be aware that this will also build any |
| required dependencies, so the lib target may be built twice (once as a |
| benchmark, and once as a dependency for binaries, benchmarks, etc.). |
| Targets may be enabled or disabled by setting the \fBbench\fP flag in the |
| manifest settings for the target. |
| .RE |
| .sp |
| \fB\-\-all\-targets\fP |
| .RS 4 |
| Benchmark all targets. This is equivalent to specifying \fB\-\-lib \-\-bins |
| \-\-tests \-\-benches \-\-examples\fP. |
| .RE |
| .SS "Feature Selection" |
| .sp |
| When no feature options are given, the \fBdefault\fP feature is activated for |
| every selected package. |
| .sp |
| \fB\-\-features\fP \fIFEATURES\fP |
| .RS 4 |
| Space or comma separated list of features to activate. These features only |
| apply to the current directory\(cqs package. Features of direct dependencies |
| may be enabled with \fB<dep\-name>/<feature\-name>\fP syntax. |
| .RE |
| .sp |
| \fB\-\-all\-features\fP |
| .RS 4 |
| Activate all available features of all selected packages. |
| .RE |
| .sp |
| \fB\-\-no\-default\-features\fP |
| .RS 4 |
| Do not activate the \fBdefault\fP feature of the current directory\(cqs |
| package. |
| .RE |
| .SS "Compilation Options" |
| .sp |
| \fB\-\-target\fP \fITRIPLE\fP |
| .RS 4 |
| Benchmark for the given architecture. The default is the host |
| architecture. The general format of the triple is |
| \fB<arch><sub>\-<vendor>\-<sys>\-<abi>\fP. Run \fBrustc \-\-print target\-list\fP for a |
| list of supported targets. |
| .sp |
| This may also be specified with the \fBbuild.target\fP |
| .URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "." |
| .RE |
| .SS "Output Options" |
| .sp |
| \fB\-\-target\-dir\fP \fIDIRECTORY\fP |
| .RS 4 |
| Directory for all generated artifacts and intermediate files. May also be |
| specified with the \fBCARGO_TARGET_DIR\fP environment variable, or the |
| \fBbuild.target\-dir\fP \c |
| .URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "." |
| Defaults |
| to \fBtarget\fP in the root of the workspace. |
| .RE |
| .SS "Display Options" |
| .sp |
| By default the Rust test harness hides output from benchmark execution to keep |
| results readable. Benchmark output can be recovered (e.g., for debugging) by |
| passing \fB\-\-nocapture\fP to the benchmark binaries: |
| .sp |
| .if n .RS 4 |
| .nf |
| cargo bench \-\- \-\-nocapture |
| .fi |
| .if n .RE |
| .sp |
| \fB\-v\fP, \fB\-\-verbose\fP |
| .RS 4 |
| Use verbose output. May be specified twice for "very verbose" output which |
| includes extra output such as dependency warnings and build script output. |
| May also be specified with the \fBterm.verbose\fP |
| .URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "." |
| .RE |
| .sp |
| \fB\-q\fP, \fB\-\-quiet\fP |
| .RS 4 |
| No output printed to stdout. |
| .RE |
| .sp |
| \fB\-\-color\fP \fIWHEN\fP |
| .RS 4 |
| Control when colored output is used. Valid values: |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04'\(bu\h'+03'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP \(bu 2.3 |
| .\} |
| \fBauto\fP (default): Automatically detect if color support is available on the |
| terminal. |
| .RE |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04'\(bu\h'+03'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP \(bu 2.3 |
| .\} |
| \fBalways\fP: Always display colors. |
| .RE |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04'\(bu\h'+03'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP \(bu 2.3 |
| .\} |
| \fBnever\fP: Never display colors. |
| .RE |
| .sp |
| May also be specified with the \fBterm.color\fP |
| .URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "." |
| .RE |
| .sp |
| \fB\-\-message\-format\fP \fIFMT\fP |
| .RS 4 |
| The output format for diagnostic messages. Valid values: |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04'\(bu\h'+03'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP \(bu 2.3 |
| .\} |
| \fBhuman\fP (default): Display in a human\-readable text format. |
| .RE |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04'\(bu\h'+03'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP \(bu 2.3 |
| .\} |
| \fBjson\fP: Emit JSON messages to stdout. |
| .RE |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04'\(bu\h'+03'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP \(bu 2.3 |
| .\} |
| \fBshort\fP: Emit shorter, human\-readable text messages. |
| .RE |
| .RE |
| .SS "Manifest Options" |
| .sp |
| \fB\-\-manifest\-path\fP \fIPATH\fP |
| .RS 4 |
| Path to the \fBCargo.toml\fP file. By default, Cargo searches in the current |
| directory or any parent directory for the \fBCargo.toml\fP file. |
| .RE |
| .sp |
| \fB\-\-frozen\fP, \fB\-\-locked\fP |
| .RS 4 |
| Either of these flags requires that the \fBCargo.lock\fP file is |
| up\-to\-date. If the lock file is missing, or it needs to be updated, Cargo will |
| exit with an error. The \fB\-\-frozen\fP flag also prevents Cargo from |
| attempting to access the network to determine if it is out\-of\-date. |
| .sp |
| These may be used in environments where you want to assert that the |
| \fBCargo.lock\fP file is up\-to\-date (such as a CI build) or want to avoid network |
| access. |
| .RE |
| .SS "Common Options" |
| .sp |
| \fB\-h\fP, \fB\-\-help\fP |
| .RS 4 |
| Prints help information. |
| .RE |
| .sp |
| \fB\-Z\fP \fIFLAG\fP... |
| .RS 4 |
| Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fP for |
| details. |
| .RE |
| .SS "Miscellaneous Options" |
| .sp |
| The \fB\-\-jobs\fP argument affects the building of the benchmark executable but |
| does not affect how many threads are used when running the benchmarks. The |
| Rust test harness runs benchmarks serially in a single thread. |
| .sp |
| \fB\-j\fP \fIN\fP, \fB\-\-jobs\fP \fIN\fP |
| .RS 4 |
| Number of parallel jobs to run. May also be specified with the |
| \fBbuild.jobs\fP \c |
| .URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "." |
| Defaults to |
| the number of CPUs. |
| .RE |
| .SH "PROFILES" |
| .sp |
| Profiles may be used to configure compiler options such as optimization levels |
| and debug settings. See |
| \c |
| .URL "https://doc.rust\-lang.org/cargo/reference/manifest.html#the\-profile\-sections" "the reference" |
| for more details. |
| .sp |
| Benchmarks are always built with the \fBbench\fP profile. Binary and lib targets |
| are built separately as benchmarks with the \fBbench\fP profile. Library targets |
| are built with the \fBrelease\fP profiles when linked to binaries and benchmarks. |
| Dependencies use the \fBrelease\fP profile. |
| .sp |
| If you need a debug build of a benchmark, try building it with |
| \fBcargo\-build\fP(1) which will use the \fBtest\fP profile which is by default |
| unoptimized and includes debug information. You can then run the debug\-enabled |
| benchmark manually. |
| .SH "ENVIRONMENT" |
| .sp |
| See \c |
| .URL "https://doc.rust\-lang.org/cargo/reference/environment\-variables.html" "the reference" " " |
| for |
| details on environment variables that Cargo reads. |
| .SH "EXIT STATUS" |
| .sp |
| 0 |
| .RS 4 |
| Cargo succeeded. |
| .RE |
| .sp |
| 101 |
| .RS 4 |
| Cargo failed to complete. |
| .RE |
| .SH "EXAMPLES" |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04' 1.\h'+01'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP " 1." 4.2 |
| .\} |
| Build and execute all the benchmarks of the current package: |
| .sp |
| .if n .RS 4 |
| .nf |
| cargo bench |
| .fi |
| .if n .RE |
| .RE |
| .sp |
| .RS 4 |
| .ie n \{\ |
| \h'-04' 2.\h'+01'\c |
| .\} |
| .el \{\ |
| . sp -1 |
| . IP " 2." 4.2 |
| .\} |
| Run only a specific benchmark within a specific benchmark target: |
| .sp |
| .if n .RS 4 |
| .nf |
| cargo bench \-\-bench bench_name \-\- modname::some_benchmark |
| .fi |
| .if n .RE |
| .RE |
| .SH "SEE ALSO" |
| .sp |
| \fBcargo\fP(1), \fBcargo\-test\fP(1) |