NBench icon indicating copy to clipboard operation
NBench copied to clipboard

RunTimeMilliseconds not working properly

Open fota666 opened this issue 6 years ago • 3 comments

I made a small test to understand the NBench infrastructure, but the results are quite surprising. The SkipWarmups is set to true, the NumberOfIterations is set to 2, but the SetUp is called three times. After the first SetUp call, the SleepTroughput method is called 80 times - I assume these calls are the estimation calls. The second and third SetUp are the actual benchmark calls, but there are only 10 SleepTroughput calls after them. And the counter's actual value is 9.59 operations In my opinion the expected outcome should be around 20 operations (sleep for 100 ms in 2000 ms time frame). If RunTimeMilliseconds is 1000, then the only change is that the first SetUp call is continued by 40 SleepTroughput calls instead of the previous 80, but the number of operations during the benchmark test is the same (~10).

[PerfSetup]
public void SetUp(BenchmarkContext context)
{
    stopWatchTotal.Start();
    addCounter = context.GetCounter(AddCounterName);
}

[PerfBenchmark(NumberOfIterations = 2, RunMode = RunMode.Throughput, RunTimeMilliseconds = 2000, TestMode = TestMode.Test, SkipWarmups = true)]
[CounterThroughputAssertion(AddCounterName, MustBe.GreaterThan, 1.2)]
public void SleepTroughput(BenchmarkContext context)
{
    stopWatchMessage.Restart();
    Thread.Sleep(100);
    addCounter.Increment();
}

fota666 avatar Oct 09 '19 10:10 fota666

i'm running into the same problem more than one year after .Any luck finding the issue, or you abandoned the usage of the library ?

NicolaAtorino avatar Feb 15 '21 22:02 NicolaAtorino

Sorry, this was in my previous life :) Unfortunately I do not remember the solution.

fota666 avatar Feb 16 '21 05:02 fota666

Actually i found the solution ! It's in my opinion a bug in the code. I am opening a pull request for this. Thanks !

NicolaAtorino avatar Feb 17 '21 10:02 NicolaAtorino