Skip to content
Skills Library
Programming · Testing

benchmarkdotnet-setup

/benchmarkdotnet-setup

Set up BenchmarkDotNet for a .NET project and interpret the results — proper benchmark classes, memory diagnostics, baselines, and reading ns/op + allocations. Use this skill whenever the user wants to benchmark code, measure performance, compare two implementations, set up BenchmarkDotNet, or asks "which is faster / how do I benchmark this / interpret these benchmark results". Always use this skill for micro-benchmarking requests; it writes correct benchmarks and explains the numbers.

Licence
MIT
Last repository change
09.08.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
2
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 09.08.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Set up BenchmarkDotNet for a .NET project and interpret the results — proper benchmark classes, memory diagnostics, baselines, and reading ns/op + allocations. Use this skill whenever the user wants to benchmark code, measure performance, compare two implementations, set up BenchmarkDotNet, or asks "which is faster / how do I benchmark this / interpret these benchmark results". Always use this skill for micro-benchmarking requests; it writes correct benchmarks and explains the numbers.

Original author description

Set up BenchmarkDotNet for a .NET project and interpret the results — proper benchmark classes, memory diagnostics, baselines, and reading ns/op + allocations. Use this skill whenever the user wants to benchmark code, measure performance, compare two implementations, set up BenchmarkDotNet, or asks "which is faster / how do I benchmark this / interpret these benchmark results". Always use this skill for micro-benchmarking requests; it writes correct benchmarks and explains the numbers.

How it works

  1. Input — point it at your code
  2. Project + benchmark class
  3. Pitfalls the skill prevents
  4. Reading the summary
  5. Principles
  6. How to use it & best prompts
Original SKILL.md headings · 54 lines, 340 words
SKILL.md preview
---
name: benchmarkdotnet-setup
description: Set up BenchmarkDotNet for a .NET project and interpret the results — proper benchmark classes, memory diagnostics, baselines, and reading ns/op + allocations. Use this skill whenever the user wants to benchmark code, measure performance, compare two implementations, set up BenchmarkDotNet, or asks "which is faster / how do I benchmark this / interpret these benchmark results". Always use this skill for micro-benchmarking requests; it writes correct benchmarks and explains the numbers.
category: Performance
version: 1.0.0
---

# BenchmarkDotNet Setup

Write correct BenchmarkDotNet benchmarks (no common pitfalls) and read the results properly — so "which is faster" is answered with data, not vibes.

## Input — point it at your code
Works on a target: a **file**, **folder**, **project**, or **GitHub URL**. Identify the methods/implementations to compare; if the user pasted results, go straight to interpretation.

## Project + benchmark class
```
dotnet add package BenchmarkDotNet
```
```csharp
[MemoryDiagnoser]                     // allocations matter as much as time
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class StringJoinBenchmarks
{
    private readonly string[] _items = Enumerable.Range(0, 1000).Select(i => i.ToString()).ToArray();

    [Benchmark(Baseline = true)]
    public string StringConcat() { var s = ""; foreach (var i in _items) s += i; return s; }

    [Benchmark]
    public string StringBuilder_() { var sb = new StringBuilder(); foreach (var i in _items) sb.Append(i); return sb.ToString(); }

    [Benchmark]
    public string StringJoin() => string.Join("", _items);
}
// Program.cs:  BenchmarkRunner.Run<StringJoinBenchmarks>();
```
Run in **Release**: `dotnet run -c Release`.

## Pitfalls the skill prevents
- Benchmarking in Debug, or without `BenchmarkRunner` (JIT/optimizations differ).
- Dead-code elimination — **return** the result so the work isn't optimized away.
- Setup work inside the `[Benchmark]` method — move it to `[GlobalSetup]`.
- Comparing without a `[Baseline]` — you need a reference point.
- Tiny inputs that measure noise, not the algorithm.

## Reading the summary
- **Mean (ns/us/ms)** — central tendency; check **StdDev/Error** for noise.
- **Ratio** — vs baseline (the headline comparison).
- **Gen0/1/2 + Allocated** — allocations and GC pressure; often the real story, not raw time.
- A faster method that allocates 10× more may lose under real load — weigh both.

## Principles
- Measure the realistic input size and shape, not a toy.
- Allocations are a first-class result — keep `[MemoryDiagnoser]` on.
- One variable at a time; keep benchmarks isolated and deterministic.
- Don't micro-optimize a path that isn't hot — confirm it matters first (`hotpath-profiler-assistant`).

## How to use it & best prompts
"Benchmark these two implementations", "is StringBuilder faster here", "set up BenchmarkDotNet for this method", "interpret these benchmark results".
Files in this package (2)
  • SKILL.md 3 KB
  • USAGE.md 1 KB

Versions

The database has no other skills named benchmarkdotnet-setup.

Database snapshot: 13.11.2026 · package version e2372b155f4e (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100microbenchmarking
    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…
  • 95bench-fast
    Run a benchmark with minimal iterations to generate assembly code via BenchmarkDotNet's DisassemblyDiagnoser. Use to generate one big assembly code file per benchmark.
  • 100split-asm
    Split BenchmarkDotNet assembly markdown files into individual files per benchmark method using splitasm. Use to break one big assembly code file per benchmark into one file per benchmark method.
  • 100revit-benchmarking
    Design, write, run, or review BenchmarkDotNet measurements that run inside Autodesk Revit with Nice3point.BenchmarkDotNet.Revit. USE FOR: comparing viable Revit API implementations, measuring a Revit hot path, applying the runner's WithCurrentConfiguration requirement, and…
  • 100microbenchmark
    Generate and run ad hoc BenchmarkDotNet microbenchmarks to validate the performance impact of a code change. Use this when asked to benchmark, profile, or validate the performance impact of a code change in dotnet/runtime at the method/API level. For end-to-end ASP.NET Core /…
  • 100performance-testing
    Benchmark indicator performance with BenchmarkDotNet. Use for Series/Buffer/Stream benchmarks, regression detection, and optimization patterns. Target 1.5x Series for StreamHub, 1.2x for BufferList.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.