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