Microbenchmarking is a skill for writing and executing benchmarks with BenchmarkDotNet, a .NET library. It is aimed at developers looking to measure and compare performance in their applications.
$ npx skills add https://github.com/dotnet/skills --skill microbenchmarkingThe microbenchmarking skill enables developers to write and run performance benchmarks using BenchmarkDotNet, a .NET benchmarking library. It provides a structured approach to measuring and comparing the performance of code segments in .NET applications. This skill helps identify performance bottlenecks and validate optimization efforts with reliable, reproducible measurements. Developers can use it to establish performance baselines, track regressions, and make data-driven decisions about code improvements. The skill integrates with the broader .NET Agent Skills ecosystem for performance optimization workflows.
Install using the command: `$ npx skills add https://github.com/dotnet/skills --skill microbenchmarking`
Run microbenchmarks to measure code performance.
Identify performance regressions in .NET applications.
Compare the performance of different algorithms or approaches.
$ npx skills add https://github.com/dotnet/skills --skill microbenchmarkinggit clone https://github.com/dotnet/skillsCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Write a microbenchmark using BenchmarkDotNet for [METHOD_OR_FUNCTION] in [PROJECT_NAME]. Include at least 3 benchmark methods: a baseline, a test with [OPTIMIZATION_TECHNIQUE], and a test with [ALTERNATIVE_APPROACH]. Use [ITERATION_COUNT] iterations and [WARMUP_COUNT] warmup iterations. Measure [METRICS] like execution time, memory allocation, and GC pressure. Output the results in a markdown table with columns for Method, Mean, Error, StdDev, Allocated, and Gen 0/1/2 GC.
**Benchmark Results for String Concatenation in `TextProcessor`** ```markdown | Method | Mean | Error | StdDev | Allocated | Gen 0 | Gen 1 | Gen 2 | |------------------------|-----------|----------|----------|-----------|--------|--------|--------| | Baseline_Concat | 1.234 ms | 0.021 ms | 0.019 ms | 1200 B | 1 | 0 | 0 | | Optimized_StringBuilder| 0.456 ms | 0.008 ms | 0.007 ms | 800 B | 0 | 0 | 0 | | Alternative_Interpolation | 0.789 ms | 0.012 ms | 0.011 ms | 950 B | 0 | 0 | 0 | ``` ### Key Insights: - **StringBuilder** is **62.5% faster** than the baseline and uses **33% less memory**. Use this for large concatenations. - **String interpolation** is a **36% improvement** over baseline but **42% slower** than StringBuilder. Ideal for small, readable operations. - **No GC pressure** in optimized methods (Gen 0 allocations only). ### Recommendation: Adopt `Optimized_StringBuilder` for all string-heavy operations in [PROJECT_NAME].
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan