microbenchmarking

Create, configure, and run BenchmarkDotNet microbenchmarks for .NET performance measurement.

1|Updated Jun 1, 2026
One-click install
npx skills add https://github.com/D1ssolve/craft-agents --skill microbenchmarking-d1ssolve
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: microbenchmarking
Source: https://github.com/D1ssolve/craft-agents/tree/main/skills/dotnet-microbenchmarking
Command: npx skills add https://github.com/D1ssolve/craft-agents --skill microbenchmarking-d1ssolve

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing correct BenchmarkDotNet benchmarks is error-prone: outdated assumptions about job configuration, runtime comparison, and execution defaults silently produce misleading measurements. This Skill provides verified, current guidance for designing, configuring, and running BDN benchmarks so .NET performance questions get answered with trustworthy data. ## Core Features & Use Cases - Benchmark Authoring: Guides correct benchmark code — returning results to prevent dead code elimination, moving initialization to [GlobalSetup], avoiding manual loops, and marking baselines for comparisons. - Comparison Strategies: Supports side-by-side method comparison, runtime comparison (net8.0 vs net9.0), NuGet package version comparison, saved-DLL baselines, GC/JIT configuration comparison, and input-scale analysis. - Cost-Aware Execution: Matches job presets (Dry, Short, Default, Medium, Long) to the situation, uses --filter to run subsets incrementally, and redirects verbose output to log files. - Diagnostics & Export: Covers MemoryDiagnoser, DisassemblyDiagnoser, EventPipeProfiler, hardware counters, statistical columns, and JSON/CSV/Markdown exporters. - Use Case: A developer reviewing a PR wants to know if a parsing change regressed performance. The Skill helps create a standalone benchmark project, compare the saved baseline DLL against current source side-by-side, and read the ratio columns from the Markdown report. ## Quick Start Ask the agent to write and run a BenchmarkDotNet benchmark comparing two implementations of a method in your .NET project, starting with a Dry job validation run.

Frequently Asked Questions about microbenchmarking

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a BenchmarkDotNet benchmark in C#?

Create a console project, add the BenchmarkDotNet package with dotnet add package, and write a public class with public methods marked [Benchmark]. Return values from benchmark methods to prevent dead code elimination, move initialization to [GlobalSetup], and use BenchmarkSwitcher.FromAssembly(...).Run(args) as the entry point.

How do I compare performance between .NET runtime versions?

Use --runtimes net8.0 net9.0 on the command line with a .csproj that lists all targets in plural <TargetFrameworks>. The first runtime listed becomes the baseline, and BDN builds separate executables per runtime and shows ratio columns side-by-side.

Why does BenchmarkDotNet hang without running benchmarks?

BenchmarkSwitcher prompts interactively to select benchmarks when no --filter argument is provided. Always pass --filter, such as --filter "*" to run everything, to avoid hanging on the interactive prompt.

How do I measure memory allocations in BenchmarkDotNet?

Add the [MemoryDiagnoser] attribute to the benchmark class, or pass --memory on the CLI. This adds Gen0/Gen1/Gen2 collection columns and an Allocated column showing bytes allocated per operation.

When should I not use BenchmarkDotNet?

Do not use BDN for profiling or tracing .NET code (use dotnet-trace or PerfView), production telemetry, or load and stress testing (use Crank or k6). BDN is designed for controlled microbenchmark comparisons, not production observation.

Why does my benchmark measure nothing or give near-zero times?

The JIT likely eliminated the computation via dead code elimination or constant folding. Return the result from the benchmark method and store inputs in fields or [Params] rather than literals so the JIT cannot precompute the answer.