CheckOps
BenchmarkDotNet
BenchmarkDotNet is the MIT-licensed .NET library for turning methods into reliable, reproducible micro-benchmarks with statistical analysis, diagnosers and exportable reports.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
BenchmarkDotNet is a .NET library that helps you transform methods into benchmarks, track their performance and share reproducible measurement experiments. The README says it is “no harder than writing unit tests”. It lives at dotnet/BenchmarkDotNet under the MIT licence.
Micro-benchmarking is easy to get wrong: JIT warm-up, dead-code elimination, garbage collection and noisy machines all distort timings. BenchmarkDotNet handles warm-up, pilot runs, iteration counts and outlier removal for you, and the README credits the perfolizer and pragmastat statistical engines for reliable, precise results.
It is used widely across the .NET ecosystem, and the project is part of the .NET Foundation organisation on GitHub.
In the quality loop, BenchmarkDotNet belongs next to unit tests. A unit test proves a method is correct; a benchmark proves it is fast enough and does not allocate more than it should. Teams often keep a benchmarks project alongside their test projects and run it before merging performance-sensitive changes, or on a schedule on dedicated hardware to track trends.
Features
- Attribute-driven: Mark methods with
[Benchmark]and run them withBenchmarkRunner.Run<T>(). - Statistics: Automatic warm-up, iteration selection, outlier detection and summary statistics.
- Parameters:
[Params]and argument sources run the same benchmark over several inputs. - Baselines: Mark one method as the baseline to see relative ratios.
- Jobs and runtimes: Compare across .NET runtimes, JIT settings and platforms in one run.
- Diagnosers: Memory allocation, threading and hardware-counter diagnosers add context to timings.
- Exporters: Markdown, HTML, CSV and other report formats for sharing.
- Protection from mistakes: Guards against common benchmarking errors, as the README states.
Pros
- De facto standard for .NET: Familiar to most .NET performance engineers.
- Reproducible: Reports capture environment details for comparison.
- MIT licence: Free for any use.
- Active: Commits on the day of review; about 11,500 stars.
- Low ceremony: Feels like writing a unit test.
Cons
- Micro, not load: It measures code paths, not system throughput under concurrent users.
- Slow runs: Accurate measurement takes time; full suites can run for many minutes.
- Needs release builds: Results are only meaningful in optimised builds on quiet machines.
- CI noise: Shared CI runners add variance; trend comparisons need care.
- .NET only: Other platforms need other harnesses, such as JMH for the JVM.
Usage and Links (Example)
A minimal benchmark:
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
public class Md5VsSha256 {
[Benchmark(Baseline = true)] public byte[] Md5() => /* ... */ null;
[Benchmark] public byte[] Sha256() => /* ... */ null;
}
BenchmarkRunner.Run<Md5VsSha256>();
Run it with dotnet run -c Release and read the summary table and exported reports.
Useful options when you go beyond the basics:
- Add
[MemoryDiagnoser]to the class to report allocated bytes and GC collections per operation. - Use
[Params(10, 100, 1000)]on a field to see how cost scales with input size. - Use
[SimpleJob(RuntimeMoniker.Net80)]and similar attributes to compare runtimes side by side. - Export results (for example GitHub-flavoured Markdown) and attach them to the pull request so reviewers see the before and after numbers.
Keep benchmarks small and focused, avoid I/O inside measured code, and return values from benchmark methods so the JIT cannot remove the work.
Resources:
Pricing
BenchmarkDotNet is free and open source under MIT.
Recommended for?
- .NET library and runtime developers comparing implementations.
- Teams guarding hot paths against performance regressions.
- Engineers writing performance-focused pull requests that need evidence.
- Not a fit for load testing services; use NBomber, k6 or JMeter for that.
Conclusion
BenchmarkDotNet is the standard micro-benchmarking harness for .NET, with sound statistics and rich diagnostics.
Run it on stable hardware in release mode, and use load-testing tools for end-to-end throughput.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with BenchmarkDotNet side by side.
JJMHJMH (Java Microbenchmark Harness) is OpenJDK's GPL-2.0 harness for building, running and analysing nano, micro, milli and macro benchmarks in Java and other JVM languages.Compare with BenchmarkDotNet
Hhyperfinehyperfine is an Apache-2.0 command-line benchmarking tool that runs shell commands repeatedly with warm-up, statistical analysis and exports, ideal for comparing CLIs and builds.Compare with BenchmarkDotNet
NNBomberNBomber is a distributed load-testing framework for .NET: write scenarios in C# or F# for HTTP, WebSockets, AMQP, SQL or any protocol, with a free personal licence and paid business plans.Compare with BenchmarkDotNet
KK6k6 is an open-source tool and cloud service that makes load testing easy for developers and QA engineers.Compare with BenchmarkDotNet
JJMeterApache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services.Compare with BenchmarkDotNet
GGatlingModern Load Testing as Code.Compare with BenchmarkDotNet