Skip to content
Testing
Skill

/codspeed-write-benchmarks

Write, fix, and maintain benchmarks so that CodSpeed measurements are valid and stable. Use this skill when adding benchmarks to a project that already runs CodSpeed, when a benchmark is noisy, flaky, or changes without a related code change, when CodSpeed reports a benchmark as

From plugin
codspeed
3953 skills1 MCP

Claude Code

$ npx -y skills add codspeedhq/codspeed --skill codspeed-write-benchmarks --agent claude-code

SKILL.md

codspeed-write-benchmarks.SKILL.md
name: codspeed-write-benchmarks
description: "Write, fix, and maintain benchmarks so that CodSpeed measurements are valid and stable. Use this skill when adding benchmarks to a project that already runs CodSpeed, when a benchmark is noisy, flaky, or changes without a related code change, when CodSpeed reports a benchmark as optimized out or measuring no execution time, when auditing or cleaning up a benchmark suite, when renaming, moving, or removing benchmarks, or when benchmarks need updating after the code under test changed. To install a benchmark framework or wire up CodSpeed for the first time, use codspeed-setup-harness instead."

Write Benchmarks

A benchmark is useful when a change in its result means a change in the code. Apply the rules below when writing a benchmark, and use them as the checklist when one misbehaves.

Run benchmarks through the CodSpeed CLI (`codspeed run`, `codspeed exec`) and read results with the CodSpeed MCP tools, not from raw framework output.

Rules

1. **Relevance**: One benchmark answers one question about a real hot path or user-facing operation. Use inputs with a realistic size and distribution.

2. **Validity**: The code under test must actually run. Use its result (return it, or pass it to the framework's black box) and keep inputs opaque to the optimizer, otherwise the work can be removed or computed at compile time. See [optimized-out benchmarks](https://codspeed.io/docs/troubleshooting).

3. **Measured region**: Measure only the operation under test. Build inputs outside the measured code. If the operation mutates its input, give every iteration a fresh copy through the framework's setup hook. Every iteration must do the same work.

4. **Determinism**: The same code must do the same work on every run. Seed random generators, use fixed-seed hashing or ordered containers, sort directory listings, and read committed fixtures. No network, clock, or environment-dependent branches. See [Benchmark Variance](https://codspeed.io/docs/instruments/cpu/regression-causes).

5. **State isolation**: A result must not depend on which benchmarks ran before it. Avoid shared caches and globals. Allocator and garbage collector state carries over between benchmarks, so allocate inputs in setup rather than in the measured code. If a micro-benchmark still moves with unrelated code changes, build it into its own binary. See [Reducing Variance](https://codspeed.io/docs/instruments/cpu/reducing-variance).

6. **Sizing**: Size each benchmark so it gives a valid result under every instrument it runs with. One benchmark can run under several instruments, and each one has its own limits:

  • **Simulation** runs the code once on a simulated CPU and excludes system calls. Use it for CPU-bound code.
  • **Walltime** measures real time over repeated rounds and includes I/O. Very short operations need more iterations per round: set the framework's time or iteration options. Avoid running benchmark processes in parallel.
  • **Memory** runs the code once and tracks every allocation. Keep a benchmark under about 2 million allocations and split larger ones. Allocation order across threads is not deterministic.

7. **Naming**: A benchmark's identity sets its history. Framework integrations use the file path, name, and parameters. The exec harness uses the `name` field, or the full command when there is none. Keep the identity stable, unique within a run, and descriptive of the scenario.

8. **Environment**: Pin the toolchain and commit lockfiles. Avoid `latest` and `stable` tags in CI. Run walltime benchmarks on [CodSpeed Macro Runners](https://codspeed.io/docs/features/macro-runners). Base and head must run on the same hardware.

Verify

1. Read the benchmark against the rules. 2. If the CodSpeed CLI is authenticated and the CodSpeed MCP tools are available, run the benchmark once with the CLI and check with the MCP tools:

  • `get_run` reports no issue on it.
  • The value is plausible and scales with input size the way the operation should, for example flat for a hash lookup and linear for a scan.
  • `query_flamegraph` shows the function under test, not setup code, as the main cost.

3. Only when stability is in question, run it again without any change.

  • Simulation and memory results should be nearly identical. A visible difference means the benchmark breaks rule 4 or 5.
  • Local walltime results vary with the machine. Use them to rank suspects only. Judge stability from CI runs on macro runners, where `get_benchmark_result` shows the spread across rounds and the outliers.

If the CLI or the MCP tools are not available, report the findings from step 1 and state that nothing was measured.

Maintain

A benchmark is noisy

1. Call `compare_runs` on two runs that disagree. If it lists environment differences (hardware, toolchain, integration version), fix rule 8 first. 2. Call `query_flamegraph` on both runs and find what differs. Allocator, garbage collector, hashing, or I/O frames point to rules 4 and 5. 3. Fix the benchmark, then verify. 4. If the variance belongs to what is measured, such as real I/O, ask the user to set a [per-benchmark regression threshold](https://codspeed.io/docs/features/customization). [Ignoring the benchmark](https://codspeed.io/docs/features/ignoring-benchmarks) is the last resort. Both are dashboard actions.

Audit a suite

List the benchmarks with `get_run`. Merge or remove benchmarks that answer the same question. Fix or remove those that break a rule. Shrink or split those that dominate the run time. Report hot paths without a benchmark, but do not add speculative ones.

Rename, move, or remove

A change to a benchmark's identity (rule 7) starts a new history, and the old benchmark shows up as skipped. Do not change it without a reason. After a rename, move, or removal, confirm the old benchmark no longer runs, then tell the user to [archive](https://codspeed.io/docs/features/archiving-benchmarks) it in the

Read more
@codspeedhq
Ships withcodspeed

🎯 <1% variance in measurements using CPU simulation - no more flaky benchmarks. 🔥 Differential flamegraphs to pinpoint exactly what got slower, commit by commit. 💬 PR comments & status checks showing performance impact directly in your workflow.

3953 skills1 MCP
Get the whole plugin

Stars on GitHub

Momentum

stars in total
395
Star history of codspeedhq/codspeed on GitHub, a chart by star-history.com

Other skills on codspeed.

codspeed-optimize

codspeed-optimize

Autonomously optimize code for performance using CodSpeed benchmarks, flamegraph analysis, and iterative improvement. Use this…

@codspeedhq@codspeedhqInstall Skill

More skills from other plugins.

api-review

api-review

Produce the "Playwright 1.xx API Review" artifact for a range of commits - the public API additions and the breaking or behavior…

playwright12d100k
@microsoft@microsoftInstall Skill
add-e2e-selectors

add-e2e-selectors

Add reliable @grafana/e2e-selectors to interactive elements and key containers in the Grafana frontend. Use when adding e2e…

grafana12d78k
@grafana@grafanaInstall Skill
promptfoo-evals

promptfoo-evals

Write, refine, run, and QA promptfoo evaluation suites: promptfooconfig.yaml, prompts, providers, vars, tests, assertions,…

@promptfoo@promptfooInstall Skill
deepeval

deepeval

DeepEval evaluation workflow for AI agents and LLM applications. TRIGGER when the user wants to evaluate or improve an AI agent,…

@confident-ai@confident-aiInstall Skill

Questions about codspeed-write-benchmarks.

Which coding agents can use codspeed-write-benchmarks?
codspeed-write-benchmarks installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.