Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Explains how to design, run, and review BenchmarkDotNet microbenchmarks for .NET, including comparative setups and job configuration.
73% 100%+27 ptsof test cases passed
Passed 22 of 22 test cases with the skill, and 16 of 22 without it.
During active local refactoring of a C# algorithm, we need quick benchmark runs that complete in 5 to 8 seconds per case instead of the 25-second default. Which CLI job option should be used?
The short iteration run passes `--job Short`
3 of 3 safety checks passed
BenchmarkDotNet can compare multiple implementations or versions in a single run, producing a side-by-side table with ratio columns and statistical analysis. This is generally preferable to separate runs because it controls for environmental variance.
When both the old and new implementations can coexist in the same compilation, define separate benchmark methods:
public class SortBenchmark
{
private int[] _data;
[GlobalSetup]
public void Setup() => _data = Enumerable.Range(0, 1000).Reverse().ToArray();
[Benchmark(Baseline = true)]
public void BubbleSort() => Sorting.BubbleSort((int[])_data.Clone());
[Benchmark]
public void QuickSort() => Sorting.QuickSort((int[])_data.Clone());
}
BDN displays a Ratio column showing each method's mean relative to the baseline. This is the simplest approach and should be preferred whenever both implementations are available at compile time.
To compare the same benchmark across different .NET runtime versions, use --runtimes on the command line or configure jobs. The .csproj must use <TargetFrameworks>net8.0;net9.0</TargetFrameworks> (plural) listing all targets:
dotnet run -c Release --framework net9.0 -- --runtimes net8.0 net9.0
var config = DefaultConfig.Instance
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core80).AsBaseline())
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core90));
Next to this one in the catalogue, plus more from the same author.