advertise with us

How to get started with BenchmarkDotNet using a simple example

BenchmarkDotNet has become the de facto standard for performance benchmarking on .NET. Nearly every video or blog post which Microsoft developers do which has some performance benchmarking uses it.

It’s really easy to get started…

1 – Install BenchmarkDotNet from NuGet
2 – Create a class which will contain your methods
3 – Use the [Benchmark] attribute on each relevant method
4 – Call BenchmarkRunner.Run on your class
5 – Run it without debugging and in release mode

The BenchmarkDotNet example below shows simple code and output for string concatenation v StringBuilder…

Note… the above example is intended to show how easy it is to get started with BenchmarkDotNet, not to show the diffs between string += v StringBuilder per se. If you are interested in what string concatenation approach is fastest check out my post -> .NET 6 string concatenation performance benchmarks.


Need Help with Your C# Projects?

We offer expert support and development services for projects of any size. Contact us for a free consultation and see how we can help you succeed.

CONTACT US NOW