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

Why I get "Collection cannot continue because kernel events were lost" message while trying to open ConcurrencyVisualizerProfiler data?

While trying to profile performance of a simple .NET Core (v3.0) method with BenchmarkDotNet library (v0.11.5) with use of ConcurrencyVisualizerProfiler attribute put on a method/class which is being measured, I receive a CvTrace file as a result of…
Lucenty
  • 664
  • 1
  • 7
  • 18
2
votes
1 answer

Difference between LLCMisses and CacheMisses on Hardware Counters

What is the difference between LLCMisses and CacheMisses?
Cleber Dantas
  • 454
  • 2
  • 9
2
votes
1 answer

BenchmarkDotNet - Benchmark Multi-Targeted Project

I have a project which targets net35, net40, net45 and netstandard2.0. (https://weblog.west-wind.com/posts/2017/Jun/22/MultiTargeting-and-Porting-a-NET-Library-to-NET-Core-20). I would like to benchmark each version of dotnet I am targeting to…
Matt M
  • 592
  • 1
  • 5
  • 27
2
votes
2 answers

How to benchmark .Net classes started from external code

I intend to use BenchmarkDotNet to test some methods inside various project. As it may be as easy as adding the Benchmark attribute to the methods, I have considerable doubt about using it in the project I work on. The project is consisting of 2…
Nestor
  • 8,194
  • 7
  • 77
  • 156
1
vote
2 answers

BenchmarkDotNet SimpleJob attribute: how so specify RuntimeMoniker equivalent to net6.0-windows

I want to benchmark classes in a WPF Class Library that multi-targets both .NET 6.0 and .NET Framework 4.8. Here's project file: WpfClassLibrary.cs:
Dan Stevens
  • 6,392
  • 10
  • 49
  • 68
1
vote
1 answer

How can I benchmark two methods each running on different framework?

I neet to compare two implementations of the same functionality but done for two frameworks: .net 4.6.2 and .net 7 How do I define this benchmark?
Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137
1
vote
2 answers

BenchmarkDotNet gives unexpected results

I was doing an investigation in calculation performance in int, float, double, decimal. And I am wondering in the results. First of all I was expecting that when we doing plus operations the winner will be int but the true is on the…
1
vote
0 answers

dotMemory vs BenchmarkDotNet discrepancies

I'm a bit confused about the differences between these two tools. In BenchmarkDotNet, when I benchmark an application while using the MemoryDiagnoser attribute, it indicates 200mb total was allocated on the managed heap after running. When I run the…
1
vote
1 answer

Can't run benchmark when I declare a constructor

I am new to benchmarking, I am trying to benchmark my controllers endpoints, but I'm getting an error BenchmarkDotNet has failed to build the auto-generated boilerplate code., when I run some tests without the class constructor everything runs…
big boy
  • 315
  • 2
  • 13
1
vote
1 answer

Reading Environment Variables in BenchmarkDotNet

I'm trying to load values from environment variables when running a BenchmarkDotNet project from the command line. I'm passing my environment variables using --envVars key:value. However, they're not being picked up by the benchmark. Here's some…
ssmith
  • 8,092
  • 6
  • 52
  • 93
1
vote
0 answers

How to benchmark asp.net core REST APIs using BenchmarkDotNet?

I do have an existing rest api project developed using asp.net core 3.1. At present we are planning to do code refactoring and optimize it. I came across BenchMarkDotNet (https://benchmarkdotnet.org/) recently. All the examples that I have come…
santosh kumar patro
  • 7,231
  • 22
  • 71
  • 143
1
vote
0 answers

Add extra statistics column for part of a function or another internal function

I have the following Benchmark code: public class BenchMarkDemo { [Benchmark] public void Foo1() { /* ... */ var stream = dosomethingElse(); var output = Bar1(stream); /* ... */ } public…
Vivek MVK
  • 1,155
  • 10
  • 19
1
vote
1 answer

How to group benchmark results by method name in BenchmarkDotNet

I am trying to output my benchmarkDotNet results as grouped by Method name. Instead it is grouped by Range. My benchmarks output looks like this: Method Range Mean Error StdDev FindPrimes 1000 23.377 us 0.1524 us 0.1425…
Tomasz Sikora
  • 1,649
  • 3
  • 19
  • 30
1
vote
2 answers

Is Dapper's QueryFirstOrDefault method really slow?

I read that Dapper is faster than EF (at least at retrieving data) and I want to confirm that so I am comparing Dapper and EntityFramework with the help of BenchmarkDotNet. So I tried this... [Benchmark] public Player…
1
vote
0 answers

Boxing vs ToString for int

I have a .net 6 project and write some logs. The usual log looks: int profileId = 100; //Any number _logger.LogInformation("profileId = {ProfileId}", profileId); Here, the boxing happens (int -> object). So, I decided to replace the code with: int…
Grigory Zhadko
  • 1,484
  • 1
  • 19
  • 33