Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentException #4

Open
JechoJekov opened this issue Jan 31, 2019 · 2 comments
Open

ArgumentException #4

JechoJekov opened this issue Jan 31, 2019 · 2 comments

Comments

@JechoJekov
Copy link

Hi,

I love the design of this lib. Still, when I tried to use it I got the an ArgumentException on the following trivial example:

var report = Measure.Candidates(
        ("Allocate", new Action(() => { var p = new byte[4096]; })),
        ("Pool", new Action(() =>
            {
                var p = ArrayPool<byte>.Shared.Rent(4096);
                ArrayPool<byte>.Shared.Return(p);
            })
        )
    )
    .NumberOfRuns(100000)
    .NumberOfWarmUpRuns(5)
    .Go();

Throws

System.ArgumentException
  HResult=0x80070057
  Message=At least one IBenchmarkCandidate must be provided
  Source=Benchmark
  StackTrace:
   at Benchmark.BuilderSteps.CandidateRunnerWithContextArgs`1.Go()
@JechoJekov
Copy link
Author

Tried Measure.Candidates<Allocate, Pool> and Measure.Candidates(new Allocate(), new Pool()) - same exception.

@xDj4
Copy link

xDj4 commented Oct 25, 2023

The problem is within the CandidateRunnerWithContextArgs class. The property "Candidates" doesn't get initialized in the constructor (or anywhere else) when using Measure.Candidates().Go().

public CandidateRunnerWithContextArgs(IBenchmarkCandidate<TContext>[] candidates)
{
    Candidates = candidates ?? throw new ArgumentNullException(nameof(candidates));
}

public CandidateRunnerWithContextArgs(
  IBenchmarkCandidate<TContext>[] candidates,
  TContext[] benchmarkTestContexts,
  int? numberOfRuns,
  TimeSpan? durationPerContext,
  TimeSpan? durationPerCandidate,
  int? numberOfWarmUpRuns,
  TContext warmUpRunBenchmarkTestContext) : this(candidates) // < Call to other constructor should be added
{
    // !!! Candidates doesn't get set...
    BenchmarkTestContexts = benchmarkTestContexts;
    FixedNumberOfRuns = numberOfRuns;
    DurationPerContext = durationPerContext;
    DurationPerCandidate = durationPerCandidate;
    FixedNumberOfWarmUpRuns = numberOfWarmUpRuns;
    WarmUpContext = warmUpRunBenchmarkTestContext;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants