Skip to content

Commit aef9cbe

Browse files
authored
Sorting parameter columns with parameter priority (#1612)
fixes #1150
1 parent d71a7e3 commit aef9cbe

21 files changed

+234
-34
lines changed

docs/articles/features/parameterization.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ name: Benchmark Parameterization
1313

1414
[!include[IntroParamsAllValues](../samples/IntroParamsAllValues.md)]
1515

16+
[!include[IntroParamsPriority](../samples/IntroParamsPriority.md)]
17+
1618
[!include[IntroArguments](../samples/IntroArguments.md)]
1719

1820
[!include[IntroArgumentsSource](../samples/IntroArgumentsSource.md)]
1921

2022
[!include[IntroArrayParam](../samples/IntroArrayParam.md)]
23+
24+
[!include[IntroArguments](../samples/IntroArgumentsPriority.md)]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
uid: BenchmarkDotNet.Samples.IntroArgumentsPriority
3+
---
4+
5+
## Sample: IntroArgumentsPriority
6+
7+
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.
8+
9+
### Source code
10+
11+
[!code-csharp[IntroArgumentsPriority.cs](../../../samples/BenchmarkDotNet.Samples/IntroArgumentsPriority.cs)]
12+
13+
### Output
14+
15+
```markdown
16+
| Method | b | A | c | d | Mean | Error | StdDev |
17+
|-------------- |--- |---- |-- |-- |---------:|--------:|--------:|
18+
| ManyArguments | ? | 100 | 1 | 2 | 103.4 ms | 0.09 ms | 0.08 ms |
19+
| Benchmark | 5 | 100 | ? | ? | 105.5 ms | 0.21 ms | 0.19 ms |
20+
| Benchmark | 10 | 100 | ? | ? | 110.5 ms | 0.14 ms | 0.14 ms |
21+
| Benchmark | 20 | 100 | ? | ? | 120.4 ms | 0.16 ms | 0.15 ms |
22+
```
23+
24+
### Links
25+
26+
* Priority BaseClass [`PriorityAttribute.cs`](xref:BenchmarkDotNet.Attributes.PriorityAttribute)
27+
* @docs.parameterization
28+
* The permanent link to this sample: @BenchmarkDotNet.Samples.IntroArgumentsPriority
29+
30+
---

docs/articles/samples/IntroParams.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ As a result, you will get results for each combination of params values.
1717
### Output
1818

1919
```markdown
20-
Method | Median | StdDev | A | B
21-
---------- |------------ |---------- |---- |---
22-
Benchmark | 115.3325 ms | 0.0242 ms | 100 | 10
23-
Benchmark | 125.3282 ms | 0.0245 ms | 100 | 20
24-
Benchmark | 215.3024 ms | 0.0375 ms | 200 | 10
25-
Benchmark | 225.2710 ms | 0.0434 ms | 200 | 20
20+
| Method | A | B | Mean | Error | StdDev |
21+
|---------- |---- |--- |---------:|--------:|--------:|
22+
| Benchmark | 100 | 10 | 115.3 ms | 0.13 ms | 0.12 ms |
23+
| Benchmark | 100 | 20 | 125.4 ms | 0.14 ms | 0.12 ms |
24+
| Benchmark | 200 | 10 | 215.5 ms | 0.19 ms | 0.18 ms |
25+
| Benchmark | 200 | 20 | 225.4 ms | 0.17 ms | 0.16 ms |
2626
```
2727

2828
### Links

docs/articles/samples/IntroParamsAllValues.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ If you want to use all possible values of an `enum` or another type with a small
2828
Benchmark | Three | ? | 301.4 ms | NA |
2929
Benchmark | Three | False | 311.5 ms | NA |
3030
Benchmark | Three | True | 320.8 ms | NA |
31-
32-
// * Legends *
33-
E : Value of the 'E' parameter
34-
B : Value of the 'B' parameter
3531
```
3632

3733
### Links
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
uid: BenchmarkDotNet.Samples.IntroParamsPriority
3+
---
4+
5+
## Sample: IntroParamsPriority
6+
7+
In order to sort columns of parameters in the results table you can use the Property `Priority` inside the params attribute. The priority range is `[Int32.MinValue;Int32.MaxValue]`, lower priorites will appear earlier in the column order. The default priority is set to `0`.
8+
9+
### Source code
10+
11+
[!code-csharp[IntroParamsPriority.cs](../../../samples/BenchmarkDotNet.Samples/IntroParamsPriority.cs)]
12+
13+
### Output
14+
15+
```markdown
16+
| Method | B | A | Mean | Error | StdDev |
17+
|---------- |--- |---- |---------:|--------:|--------:|
18+
| Benchmark | 10 | 100 | 115.4 ms | 0.12 ms | 0.11 ms |
19+
```
20+
21+
### Links
22+
23+
* Priority BaseClass [`PriorityAttribute.cs`](xref:BenchmarkDotNet.Attributes.PriorityAttribute)
24+
* @docs.parameterization
25+
* The permanent link to this sample: @BenchmarkDotNet.Samples.IntroParamsPriority
26+
27+
---

docs/articles/samples/IntroParamsSource.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ The source must be within benchmarked type!
1919
### Output
2020

2121
```markdown
22-
Method | Median | StdDev | A | B
23-
---------- |------------ |---------- |---- |---
24-
Benchmark | 115.3325 ms | 0.0242 ms | 100 | 10
25-
Benchmark | 125.3282 ms | 0.0245 ms | 100 | 20
26-
Benchmark | 215.3024 ms | 0.0375 ms | 200 | 10
27-
Benchmark | 225.2710 ms | 0.0434 ms | 200 | 20
22+
| Method | B | A | Mean | Error | StdDev |
23+
|---------- |--- |---- |---------:|--------:|--------:|
24+
| Benchmark | 10 | 100 | 115.5 ms | 0.17 ms | 0.16 ms |
25+
| Benchmark | 10 | 200 | 215.6 ms | 0.15 ms | 0.14 ms |
26+
| Benchmark | 20 | 100 | 125.5 ms | 0.19 ms | 0.18 ms |
27+
| Benchmark | 20 | 200 | 225.5 ms | 0.23 ms | 0.22 ms |
2828
```
2929

3030
### Remarks
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Generic;
2+
using System.Threading;
3+
using BenchmarkDotNet.Attributes;
4+
5+
namespace BenchmarkDotNet.Samples
6+
{
7+
public class IntroArgumentsPriority
8+
{
9+
[Params(100, Priority = 0)] // Argument priority can be combined with Params priority
10+
public int A { get; set; }
11+
12+
[Arguments(5, Priority = -10)] // Define priority just once for multiple argument attributes
13+
[Arguments(10)]
14+
[Arguments(20)]
15+
[Benchmark]
16+
public void Benchmark(int b) => Thread.Sleep(A + b);
17+
18+
[Benchmark]
19+
[ArgumentsSource(nameof(Numbers), Priority = 10)]
20+
public void ManyArguments(int c, int d) => Thread.Sleep(A + c + d);
21+
22+
public IEnumerable<object[]> Numbers()
23+
{
24+
yield return new object[] { 1, 2 };
25+
}
26+
}
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Threading;
2+
using BenchmarkDotNet.Attributes;
3+
4+
namespace BenchmarkDotNet.Samples
5+
{
6+
public class IntroParamsPriority
7+
{
8+
[Params(100)]
9+
public int A { get; set; }
10+
11+
[Params(10, Priority = -100)]
12+
public int B { get; set; }
13+
14+
[Benchmark]
15+
public void Benchmark() => Thread.Sleep(A + B + 5);
16+
}
17+
}

src/BenchmarkDotNet.Annotations/Attributes/ArgumentsAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace BenchmarkDotNet.Attributes
55
{
66
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
7-
public class ArgumentsAttribute : Attribute
7+
public class ArgumentsAttribute : PriorityAttribute
88
{
99
public object[] Values { get; }
1010

src/BenchmarkDotNet.Annotations/Attributes/ArgumentsSourceAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace BenchmarkDotNet.Attributes
44
{
55
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
6-
public class ArgumentsSourceAttribute : Attribute
6+
public class ArgumentsSourceAttribute : PriorityAttribute
77
{
88
public string Name { get; }
99

0 commit comments

Comments
 (0)