Support very-fast-running benchmarks

Avoid calling gettimeofday every time through the benchmarking loop, by keeping
track of how long each loop takes and doubling the number of iterations done
between time checks when they take less than 1/16'th of the total elapsed time.
This commit is contained in:
Gavin Andresen
2015-09-29 17:17:24 -04:00
parent 535ed9223d
commit 7072c544b5
4 changed files with 32 additions and 4 deletions

View File

@@ -36,14 +36,22 @@ BenchRunner::RunAll(double elapsedTimeForOne)
bool State::KeepRunning()
{
double now = gettimedouble();
double now;
if (count == 0) {
beginTime = now;
beginTime = now = gettimedouble();
}
else {
double elapsedOne = now - lastTime;
// timeCheckCount is used to avoid calling gettime most of the time,
// so benchmarks that run very quickly get consistent results.
if ((count+1)%timeCheckCount != 0) {
++count;
return true; // keep going
}
now = gettimedouble();
double elapsedOne = (now - lastTime)/timeCheckCount;
if (elapsedOne < minTime) minTime = elapsedOne;
if (elapsedOne > maxTime) maxTime = elapsedOne;
if (elapsedOne*timeCheckCount < maxElapsed/16) timeCheckCount *= 2;
}
lastTime = now;
++count;