When done properly, benchmarking is a great way to guide your engineering choices by comparing multiple solutions to a problem known to cause performance bottlenecks in your applications. There’s a lot of methodology involved if you want to do it right, however, that is both tricky and repetitive. And no, surrounding your code with a
Stopwatch won’t cut it.
BenchmarkDotNet makes it very easy to decorate the code that you want to test so it can be discovered, run many times, and measured. BenchmarkDotNet takes care of warmup and cooldown periods as needed, and will compute mean running times and standard deviation for you. It can also generate reports in a variety of formats.
[Benchmark(Description = "ImageSharp Resize")]
public ImageSharpSize ResizeImageSharp()
ImageSharpImage image = new ImageSharpImage(Width, Height);
return new ImageSharpSize(ResizedWidth, ResizedHeight);