Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
TheBlueMatt committed Sep 11, 2017
commit 0b1b9148cd77092d2851eeed5c8c6d5ce117452a
6 changes: 2 additions & 4 deletions src/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,20 @@ bool benchmark::State::KeepRunning()
else {
now = gettimedouble();
double elapsed = now - lastTime;
double elapsedOne = elapsed * countMaskInv;
double elapsedOne = elapsed / (countMask + 1);

@sipa sipa Sep 12, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "Remove countMaskInv caching in bench framework".

Isn't countMask always a power of two minus one? If so, we could just remember the number of bits in it, and use a shift instead of a division?

EDIT: this doesn't apply here, as you can't shift a double, but does in line 64.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna leave this be, I think we need to re-write the bench crap anyway (there is a very massive difference between runs based on the number of iterations, in many of my tests, so all of this garbage needs to just be removed).

if (elapsedOne < minTime) minTime = elapsedOne;
if (elapsedOne > maxTime) maxTime = elapsedOne;

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

if (elapsed*128 < maxElapsed) {
// If the execution was much too fast (1/128th of maxElapsed), increase the count mask by 8x and restart timing.
// The restart avoids including the overhead of this code in the measurement.
countMask = ((countMask<<3)|7) & ((1LL<<60)-1);
countMaskInv = 1./(countMask+1);
count = 0;
minTime = std::numeric_limits<double>::max();
maxTime = std::numeric_limits<double>::min();
Expand All @@ -81,7 +80,6 @@ bool benchmark::State::KeepRunning()
uint64_t newCountMask = ((countMask<<1)|1) & ((1LL<<60)-1);
if ((count & newCountMask)==0) {
countMask = newCountMask;
countMaskInv = 1./(countMask+1);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/bench/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace benchmark {
std::string name;
double maxElapsed;
double beginTime;
double lastTime, minTime, maxTime, countMaskInv;
double lastTime, minTime, maxTime;
uint64_t count;
uint64_t countMask;
uint64_t beginCycles;
Expand All @@ -55,7 +55,6 @@ namespace benchmark {
minCycles = std::numeric_limits<uint64_t>::max();
maxCycles = std::numeric_limits<uint64_t>::min();
countMask = 1;
countMaskInv = 1./(countMask + 1);
}
bool KeepRunning();
};
Expand Down