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

# Walltime Instrument Overview

> Learn how to use CodSpeed's walltime instrument for measuring real-world execution time in your benchmarks. 

The walltime instruments allow measuring the **walltime** of your benchmarks
directly in the CI. It leverages **bare-metal runners managed and provided by
CodSpeed** to measure the performance of your benchmarks with **low noise** and
**high precision**.

![Example of a walltime benchmark run](https://mintcdn.com/codspeed/_9gjNuBHMdsdxHot/instruments/walltime/assets/walltime-benchmark-sample.png?fit=max\&auto=format\&n=_9gjNuBHMdsdxHot\&q=85\&s=30cd503a285ece751baac90699d28f1f)

Example of a walltime benchmark run

## What Does the Walltime Instrument Measure?

The walltime instrument measures the **actual elapsed time** (also known as
"wall clock time") of your benchmark execution. Unlike CPU simulation which
measures simulated CPU cycles, walltime captures the real-world duration
including:

* **All code execution**: Both user-space code and system calls are included in
  the measurement, giving you a complete picture of actual runtime performance.

* **I/O operations**: Network requests, file system operations, and other I/O
  bound tasks are fully captured, making this instrument ideal for benchmarks
  that interact with external systems.

* **Parallelism effects**: Multi-threaded code benefits are accurately measured
  since walltime reflects the actual elapsed time, not CPU time across threads.

This makes the walltime instrument particularly valuable when you need to
measure performance beyond what the CPU simulation instrument can capture, such
as integration tests on API endpoints or workloads that rely on external
dependencies.

> [!NOTE]
>
> **Multiple benchmark processes**
>
> With the walltime instrument, you should try and avoid running multiple
> benchmark processes in parallel since this can lead to noisy measurements.
>
> Thus, using `pytest-xdist` or similar tools is not recommended.

## Automated Profiling

When using the walltime instrument, CodSpeed automatically collects
[profiling data and generates flamegraphs](https://codspeed.io/docs/features/profiling.md) for each
benchmark. This allows you to quickly identify performance changes and their
root causes.

![Function list](https://mintcdn.com/codspeed/CInbng288QuXBkrC/features/assets/function-list.png?fit=max\&auto=format\&n=CInbng288QuXBkrC\&q=85\&s=4e535467c1e8a6410668d5eb6bf902a0)

### Inspector Metrics

![Flamegraph inspector](https://mintcdn.com/codspeed/J_9QffCKgr3Hbs6D/instruments/walltime/assets/walltime-tooltip-explanation.excalidraw.png?fit=max\&auto=format\&n=J_9QffCKgr3Hbs6D\&q=85\&s=aca9e0b2ac5ef2f731696253c9a93e78)

When you hover over a span in the flamegraph, the inspector displays the
following metrics:

**Common metrics:**

* **Self time**: The measured execution time spent in the function body only,
  excluding time spent in child function calls.
* **Total time**: The measured execution time spent in the function including
  all its children.

**Execution events**

The walltime instrument also collects hardware events during execution. This
happens automatically when events are available. All displayed event counts are
cumulative and include events from child function calls.

* **CPU Cycles**: The number of CPU cycles elapsed.
* **Instructions**: The number of CPU instructions executed.
* **Memory R/W**: The number of memory read and write operations performed.
* **Memory Access Pattern**: A breakdown of how memory accesses were served:
  * **L1 Cache Hits**: Memory accesses served from the fastest CPU cache.
  * **L2 Cache Hits**: Memory accesses served from the second-level cache.
  * **Cache Misses**: Memory accesses that required fetching from main memory.
  * **Memory access distribution**: Total bytes read from and written to memory,
    for each level of cache. It is calculated based on the number of events, and
    the average size of each access, namely a word for a cache access, and a
    cache line for a cache miss.

> [!NOTE]
>
> **Sampling accuracy**
>
> Event counts are collected using hardware performance counter sampling. The
> deeper you navigate into leaf functions, the more susceptible these counts
> suffer from to sampling-related inaccuracies. For the most reliable data, focus
> on higher-level functions in the call stack.

## Compatibility

To enable profiling with the walltime instrument, ensure you meet the following
minimum version requirements:

| Language | Minimum required versions |
| :- | :- |
| [Python](https://codspeed.io/docs/benchmarks/python.md) | Python 3.12+ and [`pytest-codspeed >= 3.0.0`](https://github.com/CodSpeedHQ/pytest-codspeed/releases/tag/v3.0.0) |
| [Rust](https://codspeed.io/docs/benchmarks/rust.md) | [`codspeed-divan-compat >= 2.8.0`](https://github.com/CodSpeedHQ/codspeed-rust/releases/tag/v2.8.0) or [`codspeed-criterion-compat >= 2.9.1`](https://github.com/CodSpeedHQ/codspeed-rust/releases/tag/v2.9.1) |
| [C++](https://codspeed.io/docs/benchmarks/cpp.md) | [`codspeed-google-benchmark >= 1.0.0`](https://github.com/CodSpeedHQ/codspeed-cpp/releases/tag/v1.0.0) |
| [Node.js](https://codspeed.io/docs/benchmarks/nodejs/overview.md) | [`@codspeed/vitest-plugin >= 5.0.0`](https://github.com/CodSpeedHQ/codspeed-node/releases/tag/v5.0.0) or [`@codspeed/tinybench-plugin >= 5.0.0`](https://github.com/CodSpeedHQ/codspeed-node/releases/tag/v5.0.0) |
| [Go](https://codspeed.io/docs/benchmarks/go.md) | [`codspeed-go >= 0.3.0`](https://github.com/CodSpeedHQ/codspeed-go/releases/tag/v0.3.0) |
| [Java](https://codspeed.io/docs/benchmarks/java.md) | JDK 21+ with the [CodSpeed JMH integration](https://codspeed.io/docs/benchmarks/java.md) |
| [Kotlin](https://codspeed.io/docs/benchmarks/kotlin.md) | JDK 21+ with the [CodSpeed JMH integration](https://codspeed.io/docs/benchmarks/kotlin.md) |
| [Scala](https://codspeed.io/docs/benchmarks/scala.md) | JDK 21+ with the [CodSpeed JMH integration](https://codspeed.io/docs/benchmarks/scala.md) |

## Running Walltime Benchmarks

Walltime is an instrument of the CodSpeed CLI: pass `--mode walltime` to
`codspeed run`, in front of your benchmark command.

```shellscript theme={null}
codspeed run --mode walltime -- {your benchmark command}
```

With the GitHub Action, set the `mode` input instead:

```yaml theme={null}
- uses: CodSpeedHQ/action@v5
  with:
    mode: walltime
```

The rest of the setup is the one of your CI provider, see
[running benchmarks in CI](https://codspeed.io/docs/integrations/ci.md).

## Measuring in CI using Macro Runners

Walltime measures elapsed time, so it inherits the noise of the machine it runs
on. A shared CI runner sits on a host with other tenants, whose load changes
from one run to the next and moves a benchmark by more than the regressions you
want to catch. [Macro runners](https://codspeed.io/docs/features/macro-runners.md) are bare-metal machines
dedicated to your job and tuned by CodSpeed for stable measurements, so a
difference in walltime reflects a change in your code.

> [card] [Macro Runners on GitHub Actions](https://codspeed.io/docs/integrations/ci/github-actions/macro-runners.md)
>
> Change the runner label of the benchmark job

> [card] [Macro Runners on CircleCI](https://codspeed.io/docs/integrations/ci/circleci/macro-runners.md)
>
> Point the benchmark job at a CodSpeed resource class

## Next Steps

> [card] [Macro Runners](https://codspeed.io/docs/features/macro-runners.md)
>
> Learn more about CodSpeed managed bare-metal runners designed for Walltime
> benchmarks

> [card] [Profiling](https://codspeed.io/docs/features/profiling.md)
>
> Learn more about automated profiling for Walltime benchmarks

> [card] [Profiling on macOS](https://codspeed.io/docs/instruments/walltime/macos-profiling.md)
>
> Learn why system processes are missing from macOS profiles and how to work
> around it


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