Skip to content

Support Parameterized Benchmark Constructors #2482

Open
@smfields

Description

@smfields

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:

public record MyParamType(string Value1, int Value2);

public class MyBenchmark
{
    [ParamsSource(nameof(MyParamValues))]
    public MyParamType MyParameter { get; set; }

    public IEnumerable<MyParamType> 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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions