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
3
votes
1 answer

How to measure CPU usage on BenchmarkDotNet?

I am using DotNet Benchmark and I can get the memory usage information as in the table below. But I need to access how much CPU usage is in the process I have done. Does DotNetBenchmark have this feature? If not, what method should I…
egvrcn
  • 974
  • 10
  • 27
3
votes
0 answers

BenchmarkDotNet returning value allocates memory

I'm using BenchmarkDotNet with .netcore 3.1 to benchmark my code. I encounter a certain issue when I get memory allocation results even though no allocation is made. Here is an snapshot of what I am doing: [SimpleJob(RunStrategy.Monitoring,…
rerez
  • 111
  • 5
3
votes
1 answer

BenchmarkDotNet Unable to find Tests when it faces weird solution structure

I have problem with BenchmarkDotNet which I struggle to solve Here's my project structure: - | - Infrastructure | | | | - TestsBenchmark | | - MyInfra.sln | - src | - Tests | -…
Axelly
  • 589
  • 3
  • 7
  • 26
3
votes
2 answers

Turning off debugger in release mode

I have Build set to Release mode. I'm running my .NET Core 3.1 Console App with Benchmark DotNet. But it tells me, that Summary -> Benchmark was executed with attached debugger How to turn off debugger completely in Release build mode?
michasaucer
  • 4,562
  • 9
  • 40
  • 91
3
votes
1 answer

How can we pass dynamic arguments in [Arguments] tag for BenchmarkDotNet in C#?

I am trying to benchmark a method with parameters. [Benchmark] public void ViewPlan(int x) { //code here } While executing the code with [Benchmark] annotation, I got an error as "Benchmark method ViewPlan has incorrect signature. Method shouldn't…
3
votes
0 answers

Azure DevOps pass/fail build based on performance regressions

For a new project, I want to keep track of application performance by using BenchmarkDotNet to build up the performance testing suite. Does anyone know if there is anything already built to pass/fail an Azure DevOps build based on the performance…
2
votes
2 answers

C# HashSet allocate memory on each Add even within capacity

I made a simple benchmark to test HashSet.Add method and for me results looks strange. For the benchmarking I use BenchmarkDotNet available on github. Here is a full code of a benchmark: using BenchmarkDotNet.Attributes; using…
ApmeM
  • 149
  • 1
  • 1
  • 9
2
votes
1 answer

OutOfMemoryException when comparing .NET list initialized vs not initialized one using BenchmarkDotNet

I want to create a benchmark showing the difference in performance between an initialized and an uninitialized .net list, but I'm having some trouble. I tried different ways of writing this benchmark but without success. Every time I run the code, I…
Salvatore Calla'
  • 113
  • 2
  • 16
2
votes
1 answer

Why is Avg() faster than Sum()?

I've got code for test on BenchmarkDotnet.. And then I found that something felt wrong.. My projects version is C# 11.0 .NET 7.0 Nuget Package BenchMarkDotnet 0.13.5 ReadOnlyMemory readOnlyFloats; ReadOnlyMemory readOnlyDoubles; …
Ramga
  • 29
  • 3
2
votes
1 answer

Trying to evaluate two classes with a BenchmarkDotNet test

I'm trying to figure out which one of these classes below is faster, so I decided to write a BenchmarkDotNet test. public class RequestSignerBenchmark { [Benchmark] public void First() { var signer =…
nop
  • 4,711
  • 6
  • 32
  • 93
2
votes
1 answer

Change BenchmarkDotnet exporter path

The documentation says that "by default" the exporters will create a report in the .\BenchmarkDotNet.Artifacts\results path. Is there a way to override this path?
asaf92
  • 1,557
  • 1
  • 19
  • 30
2
votes
1 answer

BenchmarkDotNet, skip a benchmark on specific runtime

(https://benchmarkdotnet.org/) Is it possible to skip a single benchmark section for a specific runtime? For example i want to test several functions for 4.7.2 and Core 3.1, but one should only be benched on Core31 [Benchmark] public void…
Crimson
  • 103
  • 6
2
votes
1 answer

How to measure string interning?

I'm trying to measure the impact of string interning in an application. I came up with this: class Program { static void Main(string[] args) { _ = BenchmarkRunner.Run(); } } [MemoryDiagnoser] public class Benchmark { …
Paulo Morgado
  • 14,111
  • 3
  • 31
  • 59
2
votes
1 answer

"Wrong assembly binding redirects" when running BenchmarkDotNet

When running BenchmarkDotNet for a method in my project I get a few "Wrong assembly binding redirect" warning/error messages printed to screen. This got me a bit puzzled, as I thought assembly binding redirects is a .Net Framework concept, while my…
Petter T
  • 3,387
  • 2
  • 19
  • 31
2
votes
1 answer

Why is my MemoryManager respectively my MemoryPool implementation so slow?

I try for learning purpose to implement a MemoryManager and a MemoryPool and try how it competes with the standard implementation. But especially my MemoryManager is damn slow. Can someone point my in the direction what happened here btw whats…
Sebastian
  • 952
  • 1
  • 14
  • 41