BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

Ability to make Argument depends on the Param values

Open kant2002 opened this issue 6 years ago • 2 comments

During migration of the benchmarks to BDN here : https://github.com/dotnet/corefxlab/pull/2333 I want that one of argument would depends on the value mapped to current Param. For example to always to be 60% of the InputBufferSize

Approximate current code which I have to write

[Params(1000, 5000, 10000, 20000, 50000)] 
public int InputBufferSize;
[Benchmark] 
[Arguments(10)]
[Arguments(600)]
public void StichingRequired(int stackSize) 
{
     Span<byte> stackSpan = stackSize == 600 ? stackalloc byte[600 * InputBufferSize / 1000] :  stackalloc byte[stackSize]; 
  … some code
}

what I would like to have

[Params(1000, 5000, 10000, 20000, 50000)] 
public int InputBufferSize;
[Benchmark] 
[ArgumentsSource(nameof(StackSizes))]
public void StichingRequired(int stackSize) 
{
     Span<byte> stackSpan = stackalloc byte[stackSize]; 
  … some code
}

public IEnumerabl<object[]> StackSizes()
{
     yield return new object[] { 10 };
    // Here for each iteration of Param this value would be reevaluated.
     yield return new object[] { 600 * InputBufferSize / 1000 }; 
}

right now it seems that value not yet mapped to field with Param attribute.

kant2002 avatar Jun 03 '18 12:06 kant2002