dotnet / dotnet/BenchmarkDotNet
Support Parameterized Benchmark Constructors
- Dominant language
- C#
- Stars
- 11.5k
- Forks
- 1.1k
- Avg merge
- 6d 11h
- Merged PRs (30d)
- 12
Description
I'd like to be able to take a parameter that contains multiple values and display it in the summary table spread across multiple columns, rather than having all the values in the same column. For example, take this benchmark:
```csharp
public record MyParamType(string Value1, int Value2);
public class MyBenchmark
{
[ParamsSource(nameof(MyParamValues))]
public MyParamType MyParameter { get; set; }
public IEnumerable MyParamValues()
{
yield return new MyParamType("first", 1);
yield return new MyParamType("second", 2);
yield return new MyParamType("third", 3);
}
[Benchmark]
public void Benchmark()
{
}
}
```
Rather than having it display like this (the default):
| Method | MyParameter | Mean | Error |
|---------- |--------------------- |----------:|------:|
| Benchmark | MyPar(...)= 1 } [42] | 100.50 us | NA |
| Benchmark | MyPar(...)= 2 } [43] | 99.20 us | NA |
| Benchmark | MyPar(...)= 3 } [42] | 106.60 us | NA |
I'd like to have the value of `MyParameter` split accross multiple columns like so:
| Method| Value1| Value2| Mean| Error|
|--------|--------|--------|--------|--------|
| Benchmark| first| 1| 100.50 us| NA|
| Benchmark| second | 2 | 99.20 us| NA|
| Benchmark| third | 3| 106.60 us| NA|
Note:
- I can't switch to using arguments because I need the values of the parameters to be available in my `GlobalSetup`.
- I can't split the parameter into multiple separate parameters because I need control over how the parameters are combined (i.e. not a full cartisian product)
Any ideas on whether this is something that's possible?
Contributor guide
Assessment
This issue has not been assessed yet.