Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

Background Info

A .NET library to make Benchmarking easy! See and in-particular the Getting Started Guide the Main Features List

Hello World

Add the NuGet package Install-Package BenchmarkDotNet

Run the following code:

public class Program
    public void Slow() => Thread.Sleep(100);

    public void Fast() => Thread.Sleep(25);

    static void Main(string[] args)
        Console.WriteLine("BenchmarkDotNet - Hello World!");
        var summary = BenchmarkRunner.Run<Program>();


  • Using '+' on String (i.e. myString += "blah") compared to StringBuilder
    • Why is one faster that the other (Hint: see Diagnosers for some features that might help)
    • Does the size of the Strings involved make a difference (Hint: check out Parameterisation)
  • Replicate benchmarks from Performance Improvements in .NET Core 2.1
    • Do you get the same results?
    • Can you compare .NET Core with .NET Framework (Hint: see Configs and Job.Core)
  • Find a blog post explaining a .NET Performance 'Best Practice' i.e. like "use StringBuilder rather than concatenating Strings" (from above). Prove or Disprove the advice
    • Is it always true or does it depend on the version of .NET?
    • Does it depend on 32-bit or 64-bit? (Hint: Disassmbler will help)
    • Does the size of the inputs make a difference? (Hint: check out Parameterisation)
    • Bonus points for any graphs (Hint: see Exporters - Plots

Useful Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment