Skip to content

nbenchmark/NBenchmark

NBenchmark

Build NuGet Version NuGet Downloads .NET License: MIT

NBenchmark is the easiest way to measure the speed of your .NET code. With zero setup and a focus on simplicity, you can go from installation to your first accurate benchmark in seconds-perfect for quick checks and full performance suites alike.

📖 Full documentation →


Packages

Package Description
NBenchmark Zero-dependency core - all measurement, statistics, and file reporters.
NBenchmark.Console Adds a rich terminal table via Spectre.Console.
NBenchmark.DependencyInjection Resolves benchmark classes from an IServiceProvider so they can have constructor dependencies.
NBenchmark.Analyzers Roslyn analyzers that catch common benchmark authoring mistakes at compile time.
dotnet add package NBenchmark
dotnet add package NBenchmark.Console            # optional, for pretty terminal output
dotnet add package NBenchmark.DependencyInjection   # optional, for benchmark classes with constructor dependencies
dotnet add package NBenchmark.Analyzers            # optional, compile-time checks for benchmark correctness

Quick start

using NBenchmark;
using NBenchmark.Console;

var result = Benchmark.Run(() =>
{
    for (int i = 0; i < 1000; i++) { }
});

result.Print();
  Benchmark: 1.20 µs median
    Mean: 1.24 µs, P95: 2.00 µs
    StdDev: 360 ns
    95% CI: 1.19 µs … 1.29 µs (±50 ns)

Three usage modes

Quick mode - Benchmark.Run - a single static call, no setup required.

Suite mode - BenchmarkSuite - a fluent builder that runs multiple benchmarks side-by-side and produces a comparison table with ratios and statistical significance.

Host mode - BenchmarkHost - attribute-based discovery ([Benchmark], [BenchmarkArguments], lifecycle attributes) driven by a built-in CLI. Designed for dedicated benchmark projects.

All three modes share the same measurement engine, produce the same BenchmarkResult type, and support the same reporters and configuration.

Documentation

Getting Started Installation, quick start, key concepts
Guides Detailed walkthroughs for each mode
Dependency Injection Benchmark classes with constructor dependencies
Configuration All MeasurementOptions settings
Reporters Console, Markdown, CSV, JSON
CLI Reference All BenchmarkHost command-line flags
Advanced: Statistics How every number is calculated
Samples Runnable sample projects
FAQ Common questions

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages