FAQ (Frequently asked questions)

  • Q Why I can't install BenchmarkDotNet in Visual Studio 2010/2012/2013?
    A BenchmarkDotNet requires NuGet 3.x+ and can't be installed in old versions of Visual Studio which use NuGet 2.x. Consider to use Visual Studio 2015/2017 or Rider. See also: BenchmarkDotNet#237, roslyn#12780.

  • Q Why I can't install BenchmarkDotNet in a new .NET Core Console App in Visual Studio 2017?
    A BenchmarkDotNet supports only netcoreapp1.1+. By default, Visual Studio 2017 creates a new application which targets netcoreapp1.0. You should upgrade it up to 1.1. If your want to target netcoreapp1.0 in your main assembly, it's recommended to create a separated project for benchmarks.

  • Q I created a new .NET Core Console App in Visual Studio 2017. Now I want to run my code on CoreCLR, full .NET Framework, and Mono. How can I do it?
    A Use the following lines in your .csproj file:

<TargetFrameworks>netcoreapp1.1;net46</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>

And mark your benchmark class with the following attributes:

[CoreJob, ClrJob, MonoJob]
  • Q My source code targets old versions of .NET Framework or .NET Core, but BenchmarkDotNet requires net46 and netcoreapp1.1. How can I run benchmarks in this case?
    A It's a good practice to introduce an additional console application (e.g. MyAwesomeLibrary.Benchmarks) which will depend on your code and BenchmarkDotNet. Due to the fact that users usually run benchmarks in a develop environment and don't distribute benchmarks for users, it shouldn't be a problem.

  • Q I wrote small benchmark, but BenchmarkDotNet requires a lot of time for time measurements. How can I reduce this time?
    A By default, BenchmarkDotNet automatically chooses a number of iterations which allows achieving the best precision. If you don't need such level of precision and just want to have a quick way to get approximated results, you can specify all parameters manually. For example, you can use the SimpleJob or ShortRunJob attributes:

[SimpleJob(launchCount: 1, warmupCount: 3, targetCount: 5, invocationCount:100, id: "QuickJob")]
[ShortRunJob]