Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
Go to the documentation of this file. 13 static std::map<std::string, benchmark::BenchFunction> benchmarks_map;
14 return benchmarks_map;
19 benchmarks().insert(std::make_pair(
name, func));
26 if (std::ratio_less_equal<benchmark::clock::period, std::micro>::value) {
27 std::cerr <<
"WARNING: Clock precision is worse than microsecond - benchmarks may be less accurate!\n";
29 std::cout <<
"#Benchmark" <<
"," <<
"count" <<
"," <<
"min(ns)" <<
"," <<
"max(ns)" <<
"," <<
"average(ns)" <<
"," 30 <<
"min_cycles" <<
"," <<
"max_cycles" <<
"," <<
"average_cycles" <<
"\n";
32 for (
const auto &p: benchmarks()) {
33 State state(p.first, elapsedTimeForOne);
41 if (
count & countMask) {
49 lastTime = beginTime = now = clock::now();
54 auto elapsed = now - lastTime;
55 auto elapsedOne = elapsed / (countMask + 1);
56 if (elapsedOne < minTime) minTime = elapsedOne;
57 if (elapsedOne > maxTime) maxTime = elapsedOne;
61 uint64_t elapsedOneCycles = (nowCycles - lastCycles) / (countMask + 1);
62 if (elapsedOneCycles < minCycles) minCycles = elapsedOneCycles;
63 if (elapsedOneCycles > maxCycles) maxCycles = elapsedOneCycles;
65 if (elapsed*128 < maxElapsed) {
68 countMask = ((countMask<<3)|7) & ((1LL<<60)-1);
70 minTime = duration::max();
71 maxTime = duration::zero();
72 minCycles = std::numeric_limits<uint64_t>::max();
73 maxCycles = std::numeric_limits<uint64_t>::min();
76 if (elapsed*16 < maxElapsed) {
77 uint64_t newCountMask = ((countMask<<1)|1) & ((1LL<<60)-1);
78 if ((
count & newCountMask)==0) {
79 countMask = newCountMask;
84 lastCycles = nowCycles;
87 if (now - beginTime < maxElapsed)
return true;
91 assert(
count != 0 &&
"count == 0 => (now == 0 && beginTime == 0) => return above");
96 int64_t min_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(minTime).
count();
97 int64_t max_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(maxTime).
count();
98 int64_t avg_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>((now-beginTime)/
count).count();
99 int64_t averageCycles = (nowCycles-beginCycles)/
count;
100 std::cout << std::fixed << std::setprecision(15) <<
name <<
"," <<
count <<
"," << min_elapsed <<
"," << max_elapsed <<
"," << avg_elapsed <<
"," 101 << minCycles <<
"," << maxCycles <<
"," << averageCycles <<
"\n";
102 std::cout.copyfmt(std::ios(
nullptr));
BenchRunner(std::string name, BenchFunction func)
uint64_t perf_cpucycles(void)
Functions for measurement of CPU cycles.
std::map< std::string, BenchFunction > BenchmarkMap
std::function< void(State &)> BenchFunction
clock::time_point time_point
static BenchmarkMap & benchmarks()
static void RunAll(duration elapsedTimeForOne=std::chrono::seconds(1))