Questions tagged [benchmarkdotnet]

BenchmarkDotNet is a powerful .NET library for measuring absolute and relative code performance.

BenchmarkDotNet is open source and available on GitHub under MIT license. It is distributed as a Nuget package.

BenchmarkDotNet executes measured method multiple times and accumulates statistics on time performance of the method, with ability to differentiate a first (warm up) execution time, which might involve JIT comilcation and sustained performance after the code is JIT'ed.

Example of report from BenchmarkDotNet, comparing performance of two alternative algorithms (in this case cryptographic hash sums) -- MD5 and SHA5:

BenchmarkDotNet=v0.9.0.0
OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz, ProcessorCount=8
Frequency=2728067 ticks, Resolution=366.5599 ns
HostCLR=MS.NET 4.0.30319.42000, Arch=64-bit RELEASE [RyuJIT]


Type=Md5VsSha256  Mode=Throughput
 Method |      Median |    StdDev
------- |------------ |----------
    Md5 |  21.2912 us | 0.4373 us
 Sha256 | 107.4124 us | 1.8339 us
92 questions
5
votes
0 answers

Run BenchmarkDotNet benchmarks within Azure Pipeline

I'm trying to run benchmarks created with BenchmarkDotNet within Azure DevOps pipeline. Here is a build where I have problems. Take a look at Run benchmarks step. As you can see all tests with benchmarks are passed but actually none benchmark…
Maxim
  • 1,995
  • 1
  • 19
  • 24
5
votes
1 answer

DI containers leak memory or BenchmarksDotNet MemoryDiagnoser delivers inaccurate measurements?

Introduction We are trying to catch potential memory leaks using BenchmarksDotNet. For the simplicity of example, here is an unsophisticated TestClass: public class TestClass { private readonly string _eventName; public TestClass(string…
foxanna
  • 1,570
  • 13
  • 26
4
votes
0 answers

Run Benchmark Method run only once BenchmarkDotNet

I have a method which posts to external web api [Benchmark] public async Task SendData() { var Messages = new List() {Data.SampleMessage)}; var service= _host.Services.GetService()!; …
NoFX
  • 41
  • 5
4
votes
1 answer

How to use DependencyInjection in BenchmarkDotNet?

I'd like to use BenchmarkDotNet on some legacy code I'm working with right now. It is written in C# Net462. It is a big, old and complex system and I'd like to Benchmark some methods inside some specific class. Those classes use dependency injection…
cicerosf
  • 75
  • 8
4
votes
1 answer

Should I create separate Benchmark project?

I want to measure performance of some methods in my console application using BenchmarkDotNet library. The question is: should I create a separate project in my solution where I will copy the methods I am interested in measuring and do the measuring…
ShrikeThe
  • 77
  • 6
4
votes
1 answer

How to benchmark two different versions of the same non-NuGet library in BenchmarkDotNet?

I'm trying to use BenchmarkDotNet to prepare performance regression testing for a library. This requires that I compare the same tests with an older (stable) version of the library. Now, there's an option to give different versions of a NuGet…
Joey
  • 344,408
  • 85
  • 689
  • 683
4
votes
1 answer

How to restrict a BenchmarkDotNet job to run only on specific platforms?

I am writing an F# port of a program I wrote in native code in the past. I used BenchmarkDotNet to measure its performance. I also placed a native EXE in the application's output directory. I set my native program as the baseline benchmark and saw…
4
votes
1 answer

Getting Performance Results using benchmarkdotnet in ASP.net MVC

I am testing benchmark library to measure the performance of the code. I am reading up the documentation. I am not able to figure out how to print out results of benchmarks. I have a class called user and i want to bechmark the following…
4
votes
1 answer

First Time Call with BenchmarkDotNet

I have tried out BenchmarkDotNet with a simple test class public class BenchTest { bool First = false; [Benchmark] public void FirstTimeInitEffect() { if (First == false) { Console.WriteLine("First…
Alois Kraus
  • 13,229
  • 1
  • 38
  • 64
4
votes
0 answers

Missing method System.Collections.Immutable.ImmutableArray

I am using BenchmarkDotNet to benchmark F# code. Everything works fine if I run the benchmark from console aplication: [] let main argv = let summary = BenchmarkRunner.Run(); For some quick tests, I wanted to run…
hoonzis
  • 1,717
  • 1
  • 17
  • 32
3
votes
0 answers

Unable to use BenchmarkDotNet on WSL2: "Access to the path '/mnt/c/DumpStack.log.tmp' is denied."

I'm playing with the performance chapter from the (excellent) book Stylish F#: Crafting Elegant Functional Code for .NET and .NET Core. Here is a basic BenchmarkDotNet benchmark: open BenchmarkDotNet.Running open BenchmarkDotNet.Attributes module…
Digital Stoic
  • 1,229
  • 11
  • 20
3
votes
2 answers

What causes a memory allocation even when this Func<> variable is null?

Using BenchmarkDotNet's memory diagnoser, this code seems to allocate 12B even when called with parameters = null: public static void Usage(this ILogger logger, LogLevel logLevel, string area, string operation, Dictionary
Gilad
  • 548
  • 1
  • 7
  • 22
3
votes
0 answers

BitOperations.IsPow2 unbalanced benchmark

I am benchmarking the method BitOperations.IsPow2 with BenchmarkDotNet, but the results I got were far from my expectations. Here is the minimal code you need to reproduce the benchmark: PowerOf2Benchmark.cs using System.Numerics; using…
Marco Luzzara
  • 5,540
  • 3
  • 16
  • 42
3
votes
1 answer

Can benchmarks be created dynamically in BenchmarkDotNet?

When writing unit tests, we can add more test cases by simply adding elements to a collection, for example using TestCaseSource in NUnit. Is it possible to do something similar in BenchmarkDotNet, and create a set of benchmarks from a…
Mark Pattison
  • 2,964
  • 1
  • 22
  • 42
3
votes
1 answer

How to add extra info to BenchmarkDotNet summary?

How can I add extra informationto extend the summary information produced by BenchmarkDotNet? Like: current host name or current (Git) branch name I would like to achieve something similar to this example: Host MachineName:…
ViktorZ
  • 901
  • 1
  • 10
  • 26