BenchmarkDotNet
Powerful .NET library for benchmarking
A .NET library that measures how fast your code runs, handling warmup, CPU caching, and statistics automatically so results are reliable and comparable across runtimes.
BenchmarkDotNet is a library for .NET developers who want to measure how fast their code runs. When you need to know whether one approach to solving a problem is faster than another, or whether a change you made improved or hurt performance, you need a benchmarking tool. Writing benchmarks correctly is surprisingly difficult because of factors like CPU caching, just-in-time compilation warm-up, and background processes that can skew results. BenchmarkDotNet handles all of those details automatically so that the measurements it produces are reliable.
Using it feels similar to writing a unit test. You mark a method with a special attribute, run the benchmark runner, and BenchmarkDotNet takes care of running your code many times, warming it up, and calculating statistics. The results are printed as a table showing the average time, variation, and how different configurations compare to each other.
The library supports comparing the same code across different .NET runtimes, such as older .NET Framework versions, modern .NET, and Mono, all in a single run. You can also parameterize benchmarks to test with different input sizes automatically. Results can be exported as markdown, HTML, CSV, JSON, or charts.
BenchmarkDotNet is used by the .NET Runtime team, the .NET Compiler team, and over 27,000 other projects on GitHub. It works with code written in C#, F#, and Visual Basic, and runs on Windows, Linux, and macOS across x86, x64, and ARM processors.
The library is published as a NuGet package, which is the standard way to add dependencies in the .NET ecosystem. Full documentation and a getting-started guide are available on the project website.
Where it fits
- Compare two implementations of a function to find which one is faster.
- Measure the performance impact of a code change before merging it.
- Test the same code across multiple .NET runtime versions in a single benchmark run.
- Export benchmark results as HTML, CSV, or charts to share with your team.