Optimizing .NET Code using Benchmarks
Background Oftentimes, we come across situation where code does not perform as per expectation. What is typically approch to address it, Performance Testing - Visual Studio Load Tests or Third party tools like Locust, Vegeta, Gatling etc. Visual Studio Diagnostics Tools Or Use tools like Perfview/dotTrace/dotMemory to diagnose bottlenecks What if it is possible to Benchmark code for, Set of varying parameter(s) Different runtimes (.NET Framework versions, .NET core, Mono etc.) with option to Benchmark it Observe Memory Allocations for diagnostics Get Detailed report on execution timeline Have it as part of test suite so that it can be easily executed with every iteration involving optimized code to get immediate feedback Enter BenchmarkDotNet, a Powerful .NET library for benchmarking. It is used by DotNET Team, Roslyn, ASP.NET Core and many other projects. ...