Table of Contents

Sample: IntroArgumentsPriority

Like Params also Argument columns can be sorted in the table result through their Priority. The priority should be defined only once for multiple Arguments and will keep their inner order as they are defined in the method.

Source code

using System.Collections.Generic;
using System.Threading;
using BenchmarkDotNet.Attributes;

namespace BenchmarkDotNet.Samples
{
    public class IntroArgumentsPriority
    {
        [Params(100, Priority = 0)] // Argument priority can be combined with Params priority
        public int A { get; set; }

        [Arguments(5, Priority = -10)] // Define priority just once for multiple argument attributes
        [Arguments(10)]
        [Arguments(20)]
        [Benchmark]
        public void Benchmark(int b) => Thread.Sleep(A + b);

        [Benchmark]
        [ArgumentsSource(nameof(Numbers), Priority = 10)]
        public void ManyArguments(int c, int d) => Thread.Sleep(A + c + d);

        public IEnumerable<object[]> Numbers()
        {
            yield return new object[] { 1, 2 };
        }
    }
}

Output

|        Method |  b |   A | c | d |     Mean |   Error |  StdDev |
|-------------- |--- |---- |-- |-- |---------:|--------:|--------:|
| ManyArguments |  ? | 100 | 1 | 2 | 103.4 ms | 0.09 ms | 0.08 ms |
|     Benchmark |  5 | 100 | ? | ? | 105.5 ms | 0.21 ms | 0.19 ms |
|     Benchmark | 10 | 100 | ? | ? | 110.5 ms | 0.14 ms | 0.14 ms |
|     Benchmark | 20 | 100 | ? | ? | 120.4 ms | 0.16 ms | 0.15 ms |