Skip to content

Commit e0a9cb2

Browse files
committed
bench: Fix subtle counting issue when rescaling iteration count
Make sure that the count is a zero modulo the new mask before scaling, otherwise the next time until a measure triggers will take only 1/2 as long as accounted for. This caused the 'min time' to be potentially off by as much as 100%.
1 parent e4dbeb9 commit e0a9cb2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/bench/bench.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ bool State::KeepRunning()
6464
return true;
6565
}
6666
if (elapsed*16 < maxElapsed) {
67-
countMask = ((countMask<<1)|1) & ((1LL<<60)-1);
68-
countMaskInv = 1./(countMask+1);
67+
uint64_t newCountMask = ((countMask<<1)|1) & ((1LL<<60)-1);
68+
if ((count & newCountMask)==0) {
69+
countMask = newCountMask;
70+
countMaskInv = 1./(countMask+1);
71+
}
6972
}
7073
}
7174
lastTime = now;

0 commit comments

Comments
 (0)