Repolode
dotnet

dotnet/BenchmarkDotNet

A .NET library for turning C# methods into reproducible benchmarks, with automatic warm-up, statistics and result reports.

Stars
11,526
Forks
1,080
Open issues
168
Last commit
13 hours ago

What is it?

BenchmarkDotNet lets developers turn ordinary methods into benchmarks by marking them with attributes, similar in style to writing unit tests. The library handles the parts that are easy to get wrong by hand, including pilot runs, warm-up and measurement iterations, dead code elimination protection, and environment checks that warn about debugger attachment, DEBUG builds or virtualized hosts.

A benchmark can be parameterized with [Params], compared against a baseline, and run across multiple runtimes such as .NET Framework, .NET Core, .NET 5+, Mono and NativeAOT. Results are printed as a summary table with statistics like Mean, Error and StdDev, and can be exported to Markdown, HTML, CSV, XML, JSON and plots. It also supports memory diagnostics and disassembly listings.

BenchmarkDotNet runs on Windows, Linux and macOS and supports C#, F# and Visual Basic, with x86, x64, ARM, ARM64, Wasm and LoongArch64 architectures listed as supported.

Key features

  • 01Turn methods into benchmarks with attributes such as [Benchmark] and [Params].
  • 02Automatically handles pilot runs, warm-up, and iteration counts based on statistics.
  • 03Compare benchmarks against a baseline and run them across multiple .NET runtimes.
  • 04Export results to Markdown, HTML, CSV, JSON and plots.
  • 05Measure managed and native memory allocations and view disassembly listings.

Use cases

  • Measuring whether a code change to a hot path in a .NET service actually improves performance.
  • Comparing alternative algorithms or library APIs, such as hashing functions, on different runtimes.
  • Checking performance regressions across .NET versions or NativeAOT builds.
  • Sharing reproducible performance experiments with teammates in a standard report format.

Quick start

  1. 1

    Create a .NET console application and add the BenchmarkDotNet NuGet package

  2. 2

    Mark your methods with [Benchmark] in a class and run the benchmarks from the console app's entry point

Things to know

  • Benchmarks must run from a console application; other application types are not supported.
  • BenchmarkDotNet is not a substitute for knowing good benchmark design, and results still need careful interpretation.

Topics

FAQ

What is BenchmarkDotNet?
A .NET library for turning C# methods into reproducible benchmarks, with automatic warm-up, statistics and result reports. BenchmarkDotNet lets developers turn ordinary methods into benchmarks by marking them with attributes, similar in style to writing unit tests. The library handles the parts that are easy to get wrong by hand, including pilot runs, warm-up and measurement iterations, dead code elimination protection, and environment checks that warn about debugger attachment, DEBUG builds or virtualized hosts.
Is BenchmarkDotNet free to use? What license does it have?
BenchmarkDotNet is open source under the MIT license. Check the license terms before using it in commercial products.
Is BenchmarkDotNet still maintained?
Actively maintained. The last commit to BenchmarkDotNet was on Nov 6, 2026.
What can I use BenchmarkDotNet for?
Measuring whether a code change to a hot path in a .NET service actually improves performance. Comparing alternative algorithms or library APIs, such as hashing functions, on different runtimes. Checking performance regressions across .NET versions or NativeAOT builds. Sharing reproducible performance experiments with teammates in a standard report format.
How do I install BenchmarkDotNet?
Create a .NET console application and add the BenchmarkDotNet NuGet package Mark your methods with [Benchmark] in a class and run the benchmarks from the console app's entry point
Where can I get BenchmarkDotNet?
The source code and installation instructions are on GitHub: https://github.com/dotnet/BenchmarkDotNet

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects