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
1
vote
1 answer

BenchmarkDotNet running same benchmark multiple times

Faced with the issue that my current configuration for the benchmarks did not working properly, the reason of it is that I'm trying to run the benchmark only ones, for that as it mentioned in documentation I've to use this attribute…
semper fi
  • 53
  • 1
  • 6
1
vote
1 answer

DotNetBenchmark throws reference assembly error

I want to test the performance of some methods using BenchmarkDotnet. Therefore, I downloaded the NuGet package added the usings and implemented it like this: BenchmarkRunner.Run(); public class…
1
vote
1 answer

Get rid of the default exporters with BenchmarkDotnet

According to the documentation BenchmarkDotnet's Default exporters are: csv, html and markdown. I can see how to add my own exporter, but I can see how I can get rid of the default exporters. If there is no way to do this, is the order that the…
sgmoore
  • 15,694
  • 5
  • 43
  • 67
1
vote
1 answer

Clear Heap in Gen2 & LOH when using MemoryStream & CryptoStream

I'm trying to get some measurements to know how much footprint if "encryption/decryption process" added\. Also I'm comparing different approaches like using FileStream or returning MemoryStream (which I need in some cases). Looks like large files…
bunjeeb
  • 1,096
  • 1
  • 17
  • 32
1
vote
4 answers

C# remove carriage returns, line breaks and whitespaces from string as efficient as possible (benchmark)

In C# I have a String containing Whitespaces, carriage returns and/or line breaks. Is there a simple way to normalize large strings (100.000 to 1.000.000 characters) which are imported from textfiles as efficient as possible? To clarify what I mean:…
Daniel
  • 398
  • 2
  • 16
1
vote
1 answer

BenchmarkDotNet. Is it possible to include not warmed up results?

Assume we have some big method which is very slow on a cold start. Can we do such benchmarks and see not warmed up results?
Ssss
  • 155
  • 1
  • 12
1
vote
1 answer

Compare scaling with BenchmarkDotNet

I have a method that needs to iterate on a collection (a DataRowCollection, to be precise). The current implementation is a little slow, so I’ve been trialing a faster one. I’ve used BenchmarkDotNet to compare execution time with identical…
Sören Kuklau
  • 19,454
  • 7
  • 52
  • 86
1
vote
1 answer

Different Number of Struct Parameters Change Benchmark Results

I'm using BenchmarkDotNet to benchmark struct related code, and noticed that the performance of my benchmark depends on the number of parameters my struct contains. [MemoryDiagnoser] public class Runner { [Params(1000)] public int N; …
Morgan Kenyon
  • 3,072
  • 1
  • 26
  • 38
1
vote
1 answer

License error using Benchmark.NET + DevArt dotConnect for PostgreSQL

I'm working on an application consisting of several projects and using EntityFramework with dotConnect to run against PostgreSQL. I also have a license for dotConnect which successfully works in the main application. In parallel, I'm crafting a…
Dmitry Senin
  • 45
  • 1
  • 7
1
vote
1 answer

BenchmarkDotNet StringConcats vs StringFormat

I'm using .net core 2.0.5 on windows 10 64bit OS. Everytime, I will concate string by using string.Concat or string.Format because I learnt using string "abc" + "def" is the worse by performance. ( Memory usage is a different topic. ) - I recently…
Lost_In_Library
  • 3,265
  • 6
  • 38
  • 70
1
vote
2 answers

Can't install BenchmarkDotNet 0.10.2 on Visual Studio Ultimate 2012

I'm trying to install BenchmarkDotNet package into a brand new, blank console project on Visual Studio 2012 ultimate and I'm getting this error log: PM> Install-Package BenchmarkDotNet Attempting to resolve dependency…
Loudenvier
  • 8,362
  • 6
  • 45
  • 66
1
vote
2 answers

Exception handling in BenchmarkDotNet

I have a set of HTTP calls to benchmark: public class HttpExamples { [Benchmark] public void GetExampleCom() { var request = WebRequest.CreateHttp("http://example.com"); var webResponse = request.GetResponse(); } …
BanksySan
  • 27,362
  • 33
  • 117
  • 216
1
vote
0 answers

How to benchmark lock statement?

I've heard rumours that lock is "slow" but never tried to measure its performance myself until now. What would be the right way to benchmark it? I use the code below which produces consistent results, but I'm still not sure if I do it…
Alex G.
  • 909
  • 1
  • 9
  • 16
0
votes
0 answers

BenchmarkDotNet GlobalSetup does not handle async properly

I have a benchmark class with code similar to the following: [GlobalSetup] public async Task Setup() { await Task.Delay(1000 * 10); Console.WriteLine("Got here..."); } [Benchmark] public async Task Benchmark() { await…
Knight Steele
  • 169
  • 4
  • 14
0
votes
0 answers

How to handle database setup/cleanhup in benchmark.net?

I want to benchmark different "INSERT" implementations into a database (EF, Dapper, etc) but don't know how and where to handle the SETUP and CLEANUP of the database. There is a GlobalSetup and an IterationSetup method in Benchmark.net, but in the…
user3675331
  • 193
  • 1
  • 9