mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 18:52:29 +02:00
bench: switch to std::chrono for time measurements
std::chrono removes portability issues. Rather than storing doubles, store the untouched time_points. Then convert to nanoseconds for display. This allows for maximum precision, while keeping results comparable between differing hardware/operating systems. Also, display full nanosecond counts rather than sub-second floats.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
@@ -37,11 +38,15 @@ BENCHMARK(CODE_TO_TIME);
|
||||
|
||||
namespace benchmark {
|
||||
|
||||
using clock = std::chrono::high_resolution_clock;
|
||||
using time_point = clock::time_point;
|
||||
using duration = clock::duration;
|
||||
|
||||
class State {
|
||||
std::string name;
|
||||
double maxElapsed;
|
||||
double beginTime;
|
||||
double lastTime, minTime, maxTime;
|
||||
duration maxElapsed;
|
||||
time_point beginTime, lastTime;
|
||||
duration minTime, maxTime;
|
||||
uint64_t count;
|
||||
uint64_t countMask;
|
||||
uint64_t beginCycles;
|
||||
@@ -49,9 +54,9 @@ namespace benchmark {
|
||||
uint64_t minCycles;
|
||||
uint64_t maxCycles;
|
||||
public:
|
||||
State(std::string _name, double _maxElapsed) : name(_name), maxElapsed(_maxElapsed), count(0) {
|
||||
minTime = std::numeric_limits<double>::max();
|
||||
maxTime = std::numeric_limits<double>::min();
|
||||
State(std::string _name, duration _maxElapsed) : name(_name), maxElapsed(_maxElapsed), count(0) {
|
||||
minTime = duration::max();
|
||||
maxTime = duration::zero();
|
||||
minCycles = std::numeric_limits<uint64_t>::max();
|
||||
maxCycles = std::numeric_limits<uint64_t>::min();
|
||||
countMask = 1;
|
||||
@@ -69,7 +74,7 @@ namespace benchmark {
|
||||
public:
|
||||
BenchRunner(std::string name, BenchFunction func);
|
||||
|
||||
static void RunAll(double elapsedTimeForOne=1.0);
|
||||
static void RunAll(duration elapsedTimeForOne = std::chrono::seconds(1));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user