explaingit

dotnet/benchmarkdotnet

11,413C#Audience · developerComplexity · 2/5Setup · easy

TLDR

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.

Mindmap

mindmap
  root((BenchmarkDotNet))
    What it does
      Measures code speed
      Handles warmup
      Calculates statistics
    Supported runtimes
      NET Framework
      Modern NET
      Mono
    Output formats
      Markdown table
      HTML report
      CSV and charts
    Use cases
      Compare implementations
      Track regressions
      Parameterized tests
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Compare two implementations of a function to find which one is faster.

USE CASE 2

Measure the performance impact of a code change before merging it.

USE CASE 3

Test the same code across multiple .NET runtime versions in a single benchmark run.

USE CASE 4

Export benchmark results as HTML, CSV, or charts to share with your team.

Tech stack

C#F#Visual Basic.NETNuGet

Getting it running

Difficulty · easy Time to first run · 30min

Install via NuGet in any .NET project, no external dependencies required.

In plain English

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.

Copy-paste prompts

Prompt 1
Using BenchmarkDotNet, write a C# benchmark that compares string concatenation with the + operator versus StringBuilder. Show the full class with the [Benchmark] attribute.
Prompt 2
I have a BenchmarkDotNet results table. Explain what the Mean, Error, and StdDev columns mean and whether my optimization actually helped.
Prompt 3
Write a BenchmarkDotNet test that runs a sorting algorithm on multiple input sizes (100, 1000, 10000 elements) using the [Params] attribute.
Prompt 4
Set up a BenchmarkDotNet benchmark that compares performance across .NET Framework 4.8 and .NET 8 and exports results as a markdown table.
Open on GitHub → Explain another repo

← dotnet on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.