benchmark
benchmark copied to clipboard
Fail when calculating complexity
When calculating time complexity and the range includes 0 it fails upon evaluation.
void BM_Example(benchmark::State& state)
{
while (state.KeepRunning())
{
int i = state.range(0);
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(BM_JumpTable)->RangeMultiplier(2)->Range(0, 1)->Complexity(benchmark::o1);
Result
F:\cruft\benchmark\src\complexity.cc:270: benchmark::ComputeBigO: Check (run.complexity_n) > (0)' Failed. Did you forget to call SetComplexityN?
I get:
../src/complexity.cc:270: ComputeBigO: Check `(run.complexity_n) > (0)' failed. Did you forget to call SetComplexityN?
when i try your snippit.
i believe it's because you're using SetComplexityN
with an argument 0.
See the documentation on SetComplexityN:
404 // If this routine is called with complexity_n > 0 and complexity
report is
405 // requested for the
406 // family benchmark, then current benchmark will be part of the
computation
407 // and complexity_n will
408 // represent the length of N.
I'm not convincing myself that setting it to 0 is wrong, but it is unexpected by the library, at least. Perhaps we shouldn't use '0' as a signal that SetComplexityN wasn't called.
Dominic Hamon | Google There are no bad ideas; only good ideas that go horribly wrong.
On Fri, Jun 30, 2017 at 9:46 AM, Niklas Augustsson <[email protected]
wrote:
When calculating code complexity and the range includes 0 it crashes upon evaluation.
void BM_JumpTable(benchmark::State& state) { while (state.KeepRunning()) { int i = state.range(0); } state.SetComplexityN(state.range(0)); }
BENCHMARK(BM_JumpTable)->RangeMultiplier(2)->Range(0, 1)->Complexity(benchmark::o1);
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/benchmark/issues/410, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfIMoUVoNMp_MJfmKKRnexUrAxtinLnks5sJKfVgaJpZM4OKQUj .
The primary reason it is 0 is because of a copy paste fail on my part, from the section Calculate asymptotic complexity (Big O).
I do however consider 0 to a possible value. A possible solution would be to check if n amount of them satisfy the condition complexity_n > 0 where n is a significant subset of the total amount of benchmarks.
i'm unsure if i can come with any better suggestions since i have little reference regarding the code flow of complexity_n.
i think we should differentiate between SetComplexityN
wasn't called and SetComplexityN
was called with 0.