Skip to content

Commit 0b1b914

Browse files
committed
Remove countMaskInv caching in bench framework
We were saving a div by caching the inverse as a float, but this ended up requiring a int -> float -> int conversion, which takes almost as much time as the difference between float mul and div. There are lots of other more pressing issues with the bench framework which probably require simply removing the adaptive iteration count stuff anyway.
1 parent 31e72b2 commit 0b1b914

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/bench/bench.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,20 @@ bool benchmark::State::KeepRunning()
5555
else {
5656
now = gettimedouble();
5757
double elapsed = now - lastTime;
58-
double elapsedOne = elapsed * countMaskInv;
58+
double elapsedOne = elapsed / (countMask + 1);
5959
if (elapsedOne < minTime) minTime = elapsedOne;
6060
if (elapsedOne > maxTime) maxTime = elapsedOne;
6161

6262
// We only use relative values, so don't have to handle 64-bit wrap-around specially
6363
nowCycles = perf_cpucycles();
64-
uint64_t elapsedOneCycles = (nowCycles - lastCycles) * countMaskInv;
64+
uint64_t elapsedOneCycles = (nowCycles - lastCycles) / (countMask + 1);
6565
if (elapsedOneCycles < minCycles) minCycles = elapsedOneCycles;
6666
if (elapsedOneCycles > maxCycles) maxCycles = elapsedOneCycles;
6767

6868
if (elapsed*128 < maxElapsed) {
6969
// If the execution was much too fast (1/128th of maxElapsed), increase the count mask by 8x and restart timing.
7070
// The restart avoids including the overhead of this code in the measurement.
7171
countMask = ((countMask<<3)|7) & ((1LL<<60)-1);
72-
countMaskInv = 1./(countMask+1);
7372
count = 0;
7473
minTime = std::numeric_limits<double>::max();
7574
maxTime = std::numeric_limits<double>::min();
@@ -81,7 +80,6 @@ bool benchmark::State::KeepRunning()
8180
uint64_t newCountMask = ((countMask<<1)|1) & ((1LL<<60)-1);
8281
if ((count & newCountMask)==0) {
8382
countMask = newCountMask;
84-
countMaskInv = 1./(countMask+1);
8583
}
8684
}
8785
}

src/bench/bench.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace benchmark {
4141
std::string name;
4242
double maxElapsed;
4343
double beginTime;
44-
double lastTime, minTime, maxTime, countMaskInv;
44+
double lastTime, minTime, maxTime;
4545
uint64_t count;
4646
uint64_t countMask;
4747
uint64_t beginCycles;
@@ -55,7 +55,6 @@ namespace benchmark {
5555
minCycles = std::numeric_limits<uint64_t>::max();
5656
maxCycles = std::numeric_limits<uint64_t>::min();
5757
countMask = 1;
58-
countMaskInv = 1./(countMask + 1);
5958
}
6059
bool KeepRunning();
6160
};

0 commit comments

Comments
 (0)