> ## Documentation Index
> Fetch the complete documentation index at: https://codspeed.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# cargo-codspeed documentation

> The `cargo` subcommand to benchmark your Rust code with CodSpeed

export const BuildkiteIcon = props => <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" width={31} height={31} viewBox="0 0 31 31" fill="none" {...props}>
    <g clipPath="url(#a)">
      <path fill="#30F2A2" d="M1.652 6.448v9.005l9.011 4.509V10.95l-9.01-4.503Zm18.017 0v9.005l9.011-4.502-9.011-4.503Z" />
      <path fill="#14CC80" d="M19.668 15.459v9.006l9.011-4.503V10.95l-9.011 4.508Z" />
      <path fill="#14CC80" d="M10.664 10.95v9.012l9.011-4.503V6.448l-9.01 4.503Z" />
    </g>
    <defs>
      <clipPath id="a">
        <path fill="#fff" d="M1.652 6.448H28.68v18.055H1.652z" />
      </clipPath>
    </defs>
  </svg>;

export const GitLabIcon = props => <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" width={31} height={31} viewBox="0 0 31 31" fill="none" {...props}>
    <g clipPath="url(#a)">
      <path fill="#E24329" d="m29.301 12.446-.041-.105-3.968-10.356a1.034 1.034 0 0 0-1.026-.65c-.217.012-.425.09-.597.224-.17.137-.292.324-.352.534l-2.68 8.197H9.79l-2.68-8.197a1.041 1.041 0 0 0-.352-.536 1.063 1.063 0 0 0-1.214-.065c-.184.117-.327.289-.408.492l-3.976 10.35-.04.106a7.368 7.368 0 0 0 2.445 8.515l.013.011.037.026 6.044 4.526 2.99 2.264 1.822 1.375a1.224 1.224 0 0 0 1.482 0l1.821-1.375 2.99-2.264 6.082-4.553.015-.013a7.371 7.371 0 0 0 2.441-8.506Z" />
      <path fill="#FC6D26" d="m29.302 12.446-.04-.105a13.404 13.404 0 0 0-5.336 2.399l-8.715 6.59 5.551 4.195 6.081-4.554.015-.012a7.371 7.371 0 0 0 2.444-8.513Z" />
      <path fill="#FCA326" d="m9.656 25.525 2.99 2.263 1.822 1.375a1.225 1.225 0 0 0 1.482 0l1.821-1.375 2.99-2.263s-2.586-1.957-5.553-4.196c-2.968 2.24-5.552 4.196-5.552 4.196Z" />
      <path fill="#FC6D26" d="M6.493 14.74a13.386 13.386 0 0 0-5.334-2.405l-.04.105a7.368 7.368 0 0 0 2.445 8.516l.013.01.037.026 6.044 4.527 5.552-4.196-8.717-6.584Z" />
    </g>
    <defs>
      <clipPath id="a">
        <path fill="#fff" d="M.055.097h30.27v30.27H.056z" />
      </clipPath>
    </defs>
  </svg>;

export const GitHubIcon = props => <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" viewBox="0 0 32 31" width={32} height={31} fill="none" {...props}>
    <path fill="#F4F4F5" fillRule="evenodd" d="M16.093 1.187c-7.778 0-14.066 6.334-14.066 14.17A14.159 14.159 0 0 0 11.645 28.8c.7.141.955-.305.955-.68 0-.329-.023-1.455-.023-2.628-3.913.845-4.728-1.69-4.728-1.69-.628-1.641-1.56-2.064-1.56-2.064-1.28-.867.093-.867.093-.867 1.42.093 2.166 1.454 2.166 1.454 1.258 2.158 3.284 1.549 4.099 1.173.116-.915.489-1.548.885-1.9-3.121-.329-6.404-1.549-6.404-6.992 0-1.548.558-2.815 1.443-3.8-.14-.352-.629-1.807.14-3.754 0 0 1.188-.376 3.866 1.454a13.524 13.524 0 0 1 3.516-.469c1.188 0 2.399.164 3.517.47 2.678-1.83 3.866-1.455 3.866-1.455.768 1.947.279 3.402.14 3.754.908.985 1.443 2.252 1.443 3.8 0 5.443-3.283 6.64-6.427 6.992.512.445.954 1.29.954 2.627 0 1.9-.023 3.426-.023 3.895 0 .375.257.821.955.68a14.16 14.16 0 0 0 9.618-13.443c.023-7.836-6.288-14.17-14.043-14.17Z" clipRule="evenodd" />
  </svg>;

<div className="flex flex-row gap-2 items-center">
  <a className="border-none" target="_blank" href="https://github.com/CodSpeedHQ/codspeed-rust/actions">
    <img className="my-0" noZoom src="https://github.com/CodSpeedHQ/codspeed-rust/workflows/CI/badge.svg" alt="CI Status" />
  </a>

  <a className="border-none" target="_blank" href="https://crates.io/crates/cargo-codspeed">
    <img className="my-0" noZoom src="https://img.shields.io/crates/v/cargo-codspeed" alt="Crates.io Version" />
  </a>
</div>

## Overview

`cargo-codspeed` is a Cargo subcommand for running performance benchmarks with
CodSpeed. It provides an easy way to build and run benchmarks for Rust projects
with CodSpeed integration.

## Installation

### With `cargo`

```bash theme={null}
cargo install cargo-codspeed --locked
```

### With `cargo-binstall` (recommended in CI)

[`cargo-binstall`](https://github.com/cargo-bins/cargo-binstall) enables you to
install binaries directly without having to build from the source(with
`cargo install`) every time.

If you don't have installed yet, you can install it with:

```bash theme={null}
cargo install cargo-binstall
```

You can then install `cargo-codspeed` with:

```bash theme={null}
cargo binstall cargo-codspeed
```

## Usage

### Building Benchmarks

Build your benchmarks for CodSpeed:

```bash theme={null}
cargo codspeed build
```

### Running Benchmarks

Run the previously built benchmarks:

```bash theme={null}
cargo codspeed run
```

### The `--measurement-mode` flag

When building benchmarks, you can specify the measurement mode using the
`--measurement-mode` / `-m` flag. This determines which CodSpeed instrument can
be used to run your benchmarks.

```bash theme={null}
# First build the benchmarks:
cargo codspeed build -m simulation

# Then run them:
cargo codspeed run -m simulation
```

The `--measurement-mode` flag can take the following values:

* **`simulation`**: Runs benchmarks once on a [simulated CPU](/instruments/cpu)
  for consistent measurements.
* **`walltime`**: Measures [wall-clock time](/instruments/walltime) for
  real-world scenarios.
* **`memory`**: Benchmarks are run once using
  [memory profiling](/instruments/memory) to track heap allocations and memory
  usage.

If you omit the `--measurement-mode` flag, the default behavior is to build for
simulation mode.
