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

> Learn how the CodSpeed metrics work

# Impact Metrics

## Benchmark performance impact

The performance impact denotes an <strong style={{color: 'green'}}>improvement</strong> or <strong style={{color: 'red'}}>regression</strong> in performance of a benchmark. It is
calculated by comparing the benchmark time measurement of the head commit with
the time measurement of the base commit.

$$
impact = \frac{speed - baseSpeed}{baseSpeed}
$$

A <strong style={{color: 'red'}}>negative</strong> performance metric means that
the benchmark is slower than the previous commit. The closer its value is to
`-1`, the slower it is.

$$
-1 \lt impact \lt 0
$$

A <strong style={{color: 'green'}}>positive</strong> performance metric means
that the benchmark is faster than the previous commit. Its value can go up to
$+\infty$ to denote massive speed improvements.

$$
0 \lt impact \lt +\infty
$$

Naturally, when the benchmark is as fast as the previous commit, the performance
metric is $0$.

## Regression threshold

On the settings page of a project, you can set a threshold for a regression to
be considered a regression. By default, this value is set to `10%` (which is
equivalent to `0.1`). The value can be set from `0%` to `50%` by an admin of the
project. More information about setting the threshold can be found in the
[customization documentation](/features/customization#regression-threshold).

Individual benchmarks can have their own custom regression thresholds that
override the project-level setting. See the
[customization documentation](/features/customization#per-benchmark-regression-thresholds)
for details on configuring per-benchmark thresholds.

## Commit performance impact

To get the overall performance impact of a commit, we take the geometric mean of
the benchmarks whose change exceeds their regression threshold (the "changed"
benchmarks). In that case, benchmarks within the threshold are not taken into
account.

Let $k$ be the number of changed benchmarks and $changedImpact$ their list of
impacts.

$$
commitImpact = \left(\prod_{i=0}^{k-1} \left(1 + changedImpact_i\right)\right)^{1/k} - 1
$$

> *For example, with impacts `[0.3, 0.3, 0.3, -0.11]` and a threshold of `0.1`,
> all four benchmarks exceed their threshold, so the overall commit impact is
> approximately `+0.20`.*

If no benchmark exceeds its threshold, we fall back to the geometric mean of
**all** benchmarks.

<Note>
  The overall commit impact reflects the aggregate story of the run. Regressions
  above threshold are surfaced **independently** of this number: they are listed
  in the report, trigger the performance status check to fail, and are flagged in
  the pull request comment — even when the overall impact is positive.
</Note>

<Note>
  We use the geometric mean rather than the arithmetic mean because it is less
  sensitive to outliers and composes the way relative performance changes
  naturally do.
</Note>

## Baseline report selection

To create a performance impact, we need to compare the execution speed of the
benchmarks against a baseline of those benchmarks' execution speed. Depending on
the context of the run, the baseline report can be different.

### Pull Request

When triggering a CodSpeed run on a pull request between a `head` branch and a
`base` branch, the baseline report will be the report of the latest commit of
the `base` branch with a CodSpeed run.

<Note>
  **Checked-out commit of a Pull Request in GitHub Actions**

  By default, when using the
  [`action/checkout`](https://github.com/actions/checkout) in GitHub Actions, the
  checked-out commit of a pull request will be the
  [merge commit](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request)
  of the pull request. This means that GitHub will create a merge commit **M**
  between the `base` branch and the `head` branch, and use it as the checked-out
  commit.
</Note>

<img src="https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/features/understanding-the-metrics/assets/pull-request-base.dark.png?fit=max&auto=format&n=jKaxX6yy-Kzw1C-0&q=85&s=8e5c8676e654531a4900ee5aa9e49a72" alt="Pull Request Base" className="w-full max-w-lg mx-auto" width="3035" height="1329" data-path="features/understanding-the-metrics/assets/pull-request-base.dark.png" />

In this case, the report will be between the `HEAD` commit **C** of the `base`
branch and the merge commit **M**. The report will thus only include the changes
of commits **B1** and **B2**.

<Note>
  Every time a new commit is pushed on the `feat-branch`, the baseline report will
  be updated to the latest commit of the `base` branch with a CodSpeed run.
</Note>

<Warning>
  This pull request base selection algorithm will only work on `pull_request`
  event for GitHub Actions and `merge_request_event` for GitLab CI. If you run
  CodSpeed on a different event, the branch base selection algorithm defined below
  will be used instead.
</Warning>

### Branch

When triggering a CodSpeed run following a push on a branch, the baseline report
will be the report of the closest commit of the branch.

<img src="https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/features/understanding-the-metrics/assets/branch-base.dark.png?fit=max&auto=format&n=jKaxX6yy-Kzw1C-0&q=85&s=6ac9a6a67ea01b31ab0235e06906882e" alt="Branch Base" className="w-full max-w-lg mx-auto" width="2855" height="814" data-path="features/understanding-the-metrics/assets/branch-base.dark.png" />

<Note>
  In this example, a report already exists for the commit **B** of the `main`
  branch. A new commit **C** is pushed on the `main` branch. The baseline report
  for **C** will be the report of the commit **B**.
</Note>

## Performance impact Gauge

The performance impact gauge is a visual representation of the performance
impact, displayed in multiple places of the CodSpeed UI.

Some examples of the gauge with their corresponding impact values:

<div
  style={{
display: "flex",
justifyContent: "space-between",
marginBottom: "20px",
}}
>
  <div style={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
    <img src="https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/features/understanding-the-metrics/assets/gauge/-0.75.png?fit=max&auto=format&n=jKaxX6yy-Kzw1C-0&q=85&s=0d8e4a54c8c63e2c3086fa7c5bb49f51" alt="Gauge -0.75" style={{ maxWidth: "100px" }} width="256" height="224" data-path="features/understanding-the-metrics/assets/gauge/-0.75.png" />

    <strong>-0.75</strong>
  </div>

  <div style={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
    <img src="https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/features/understanding-the-metrics/assets/gauge/-0.2.png?fit=max&auto=format&n=jKaxX6yy-Kzw1C-0&q=85&s=77627c3fb797ec5a43f60db876f9b221" alt="Gauge -0.2" style={{ maxWidth: "100px" }} width="256" height="224" data-path="features/understanding-the-metrics/assets/gauge/-0.2.png" />

    <strong>-0.2</strong>
  </div>

  <div style={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
    <img src="https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/features/understanding-the-metrics/assets/gauge/0.png?fit=max&auto=format&n=jKaxX6yy-Kzw1C-0&q=85&s=74220231d450edd581e49f58979676ae" alt="Gauge 0" style={{ maxWidth: "100px" }} width="256" height="224" data-path="features/understanding-the-metrics/assets/gauge/0.png" />

    <strong>0</strong>
  </div>

  <div style={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
    <img src="https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/features/understanding-the-metrics/assets/gauge/0.3.png?fit=max&auto=format&n=jKaxX6yy-Kzw1C-0&q=85&s=582d9e859871bdb1d2082e387bfe00ff" alt="Gauge 0.3" style={{ maxWidth: "100px" }} width="256" height="224" data-path="features/understanding-the-metrics/assets/gauge/0.3.png" />

    <strong>0.3</strong>
  </div>

  <div style={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
    <img src="https://mintcdn.com/codspeed/jKaxX6yy-Kzw1C-0/features/understanding-the-metrics/assets/gauge/1.5.png?fit=max&auto=format&n=jKaxX6yy-Kzw1C-0&q=85&s=65e7813d018f72d54715c19113548319" alt="Gauge 1.5" style={{ maxWidth: "100px" }} width="256" height="224" data-path="features/understanding-the-metrics/assets/gauge/1.5.png" />

    <strong>1.5</strong>
  </div>
</div>

<Note>
  To make it easier to spot regressions and improvements, the mapping between the
  actual performance impact value and the gauge is not linear.
</Note>

## Next Steps

<Columns cols={2}>
  <Card title="Set Up Automated Performance Checks" href="/features/performance-checks" icon="shield-check">
    Configure GitHub branch protection to automatically block performance
    regressions
  </Card>

  <Card title="Debug Performance Issues" href="/features/profiling" icon="bars-sort">
    Use flame graphs and profiling data to identify and fix bottlenecks
  </Card>
</Columns>

<Columns cols={2}>
  <Card title="Customize Regression Thresholds" href="/features/customization" icon="gear">
    Fine-tune regression sensitivity for your project's requirements
  </Card>

  <Card title="Create Comprehensive Benchmarks" href="/benchmarks/overview" icon="code">
    Build a robust benchmark suite to catch performance issues early
  </Card>
</Columns>
