Use Benchly to automatically export graphical BenchmarkDotNet results without installing additional tools such as R. Benchly runs seamlessly as part of benchmark execution and is compatible with GitHub actions. Benchly produces high quality charts using Plotly.NET.
Benchly supports 4 different plots:
- Column chart: shows the relative latency of results.
- Box plot: shows the relative variability of results.
- Histogram: shows distribution of results.
- Timeline: shows the latency trend through time.
Benchly is installed from NuGet:
dotnet add package Benchly
Add plot exporter attributes to your benchmark:
[BoxPlot(Title = "Box Plot", Colors = "skyblue,slateblue")]
[ColumnChart(Title = "Column Chart", Colors = "skyblue,slateblue")]
[MemoryDiagnoser, SimpleJob(RuntimeMoniker.Net60), SimpleJob(RuntimeMoniker.Net48)]
public class Md5VsSha256
{
private const int N = 10000;
private readonly byte[] data;
private readonly SHA256 sha256 = SHA256.Create();
private readonly MD5 md5 = MD5.Create();
public Md5VsSha256()
{
data = new byte[N];
new Random(42).NextBytes(data);
}
[Benchmark]
public byte[] Sha256() => sha256.ComputeHash(data);
[Benchmark]
public byte[] Md5() => md5.ComputeHash(data);
}
Plots are written to the results directory after running the benchmarks, like the built in exporters:
Benchly uses Plotly.NET. Ironically for a performance measurement tool, whilst convenient this is not a performant approach to generating plots. Internally, FSharp invokes plotly.js running inside a headless instance of chromium managed by pupetteer. The first time benchly runs, chromium will be downloaded into the bin directory causing short delay.
Based on this repo that shows how to export benchmark data to Excel: https://github.com/CodeTherapist/BenchmarkDotNetXlsxExporter