microbenchmarking
What it does
This skill guides writing and reviewing BenchmarkDotNet benchmarks, which measure how fast small parts of .NET code run. It is for developers who want reliable timing for a specific method or change.
When to use it
- βWhen you want to measure how fast a small piece of .NET code runs.
- βWhen you need to write or review a BenchmarkDotNet benchmark.
- βWhen you want to compare two implementations with proper measurement.
Skill link
https://github.com/dotnet/skills/blob/main/plugins/dotnet-diag/skills/microbenchmarking/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βWrite a BenchmarkDotNet benchmark that compares two ways of parsing integers in my C# code.β
5 new skills a week. 1 minute to read.
How it works
The agent reads the current benchmark guidance, writes the benchmark with the right job settings and parameters, and checks the setup against common mistakes before running it.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Benchmark Authoring Guidelines
BenchmarkDotNet (BDN) is a .NET library for writing and running microbenchmarks. Throughout this skill, "BDN" refers to BenchmarkDotNet.
Note: Evaluations of LLMs writing BenchmarkDotNet benchmarks have revealed common failure patterns caused by outdated assumptions about BDN's behavior β particularly around runtime comparison, job configuration, and execution defaults that have changed in recent versions. The reference files in this skill contain verified, current information. You MUST read the reference files relevant to the task before writing any code β your training data likely contains outdated or incorrect BDN patterns.
Key concepts
- Job β describes how to run a benchmark: runtime, iteration counts, launch count, run strategy, and environment settings. Multiple jobs can be configured to run the same benchmarks under different conditions.
- Benchmark case β one method Γ one parameter combination Γ one job. The atomic unit BDN measures.
- Operation β the logical unit of work being measured. All BDN output columns (Mean, Error, etc.) report time per operation.
- Invocation β a single call to the benchmark method. By default, 1 invocation = 1 operation. With
OperationsPerInvoke=N, each invocation counts as N operations. - Iteration β a timed batch of invocations. BDN measures the total time for all invocations in an iteration, then divides by the total operation count to get per-operation time.
Benchmarks are comparative instruments
A single benchmark number has limited value β it can confirm the order of magnitude of a measurement, but the exact value changes across machines, operating systems, and runtime configurations. Benchmarks produce the most useful information when compared against something. Before writing benchmarks, identify the comparison axis for the current task:
- Approaches (A vs B): comparing alternative implementations side-by-side in the same run.
- Runtimes: comparing the same code across .NET versions (e.g., net8.0 vs net9.0).
- Package versions: comparing different versions of a NuGet dependency.
- Builds (before/after): comparing a saved DLL of the old code against the current source.
- Runtime configuration (GC mode, JIT settings): understanding how runtime settings affect performance β compared via multiple jobs in a single run.
- Scale (N=100 vs N=1000): understanding how performance changes as input size grows.
- Hardware/OS: comparing across different machines or operating systems β requires separate runs on each environment.
- Historical measurements: comparing against measurements recorded at a previous point in time.
BDN can compare the first six axes side-by-side in a single run, but each requires specific CLI flags or configuration that differ from what you might expect β read references/comparison-strategies.md for the correct approach for each strategy before configuring a comparison.
Use cases and benchmark lifecycle
There are four distinct reasons a developer writes a benchmark, and each one changes how the benchmark should be designed and where it should live:
Coverage suite: Write benchmarks to maximize coverage of real-world usage patterns so that regressions affecting most users are caught. These benchmarks are permanent β they belong in the project's benchmark suite, follow its conventions (directory structure, base classes, naming), and are checked in.
Issue investigation: Someone has reported a specific performance problem. Write benchmarks to reproduce and diagnose that specific issue. These benchmarks are task-scoped β they persist across the investigation (reproduce β isolate β verify fix) but are not part of the permanent suite.
Change validation: A developer has a PR or change and wants to understand its performance characteristics before merging. These benchmarks are task-scoped β they persist across the review cycle but are not checked in.
Development feedback: A developer is actively working on a task and wants to use benchmarks to evaluate approaches and get information early. These benchmarks are task-scoped and throwaway β they persist across the development session but are deleted when the decision is made.
For use case 1, add to the existing benchmark project following its conventions. For use cases 2β4, create a standalone project in a working directory that persists
FAQ
Why not just time the code with a stopwatch?
BenchmarkDotNet handles warm-up, repeated runs and noise, which makes the numbers more reliable.
Does it check for common mistakes?
Yes. It covers common mistakes in runtime comparison and job setup.
Is BenchmarkDotNet required?
Yes. The skill is built around that library for .NET benchmarking.
Details
Original description by the author
Activate this skill when BenchmarkDotNet (BDN) is involved in the task β creating, running, configuring, or reviewing BDN benchmarks. Also activate when microbenchmarking .NET code would be useful and BenchmarkDotNet is the likely tool. Consider activating when answering a .NET performance question requires measurement and BenchmarkDotNet may be needed. Covers microbenchmark design, BDN configuration and project setup, how to run BDN microbenchmarks efficiently and effectively, and using BDN for side-by-side performance comparisons. Do NOT use for profiling/tracing .NET code (dotnet-trace, Per
repo: dotnet/skills
Popularity
- GitHub stars
- 5.8k
- Ranking position
- #14579
- License
- MIT
- Updated
- 11/2/2026
Comments
- β¦
More skills from this repository
create-custom-agent
5.8kHelps your agent create VS Code custom agent files with their own tools, instructions and handoffs to other agents.
create-skill
5.8kHelps your agent create a new agent skill with a valid name, a clear trigger description and a SKILL.md file that follows the standard.
csharp-scripts
5.8kHelps your agent run a small C# program as a single file with the .NET command line tool, without creating a full project.
dotnet-pinvoke
5.8kHelps your agent call native C or C++ libraries from .NET correctly, covering signatures, string handling, memory and safe handles.
Similar skills
test-driven-development
311kTeaches your agent to write a failing test first, watch it fail, then write the smallest code that passes, before building any feature or fix.
verification-before-completion
311kTeaches your agent to run real checks and read their output before claiming that a task, fix, or build is complete or passing.
migrate-to-shoehorn
310kReplaces risky type casts in your test files with the shoehorn library, so tests can use partial data and still pass type checks.