aboutsummaryrefslogtreecommitdiff
path: root/src/bench/bench.cpp
diff options
context:
space:
mode:
authorGavin Andresen <[email protected]>2015-09-29 17:17:24 -0400
committerGavin Andresen <[email protected]>2015-09-30 09:24:42 -0400
commit7072c544b52774ac5a22835121e8e2747ad61158 (patch)
tree61bab3fc434f5c058ef43a73cf2cc3b4fd78661a /src/bench/bench.cpp
parentSimple benchmarking framework (diff)
downloaddiscoin-7072c544b52774ac5a22835121e8e2747ad61158.tar.xz
discoin-7072c544b52774ac5a22835121e8e2747ad61158.zip
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.
Diffstat (limited to 'src/bench/bench.cpp')
-rw-r--r--src/bench/bench.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp
index 572080760..89c3b0cc2 100644
--- a/src/bench/bench.cpp
+++ b/src/bench/bench.cpp
@@ -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;