> ## 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

[![CI Status](https://github.com/CodSpeedHQ/codspeed-rust/workflows/CI/badge.svg)](https://github.com/CodSpeedHQ/codspeed-rust/actions)

[![Crates.io Version](https://img.shields.io/crates/v/cargo-codspeed)](https://crates.io/crates/cargo-codspeed)

## 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](https://codspeed.io/docs/instruments/cpu.md)
  for consistent measurements.
* **`walltime`**: Measures [wall-clock time](https://codspeed.io/docs/instruments/walltime.md) for
  real-world scenarios.
* **`memory`**: Benchmarks are run once using
  [memory profiling](https://codspeed.io/docs/instruments/memory.md) to track heap allocations and memory
  usage.

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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.