diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-11-10 08:20:15 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-11-10 08:20:43 +0100 |
commit | fe503e118f08a9a781d8cc1a6cdde5a615178433 (patch) | |
tree | 06696dfba44b36275d2b2872c87b9c20ff45b5cb | |
parent | 6e4e98ee8ce2da3cca2e2fd210e9e8dbc9b1c936 (diff) | |
parent | 620bae34cfe10e20daa0dcec7e4b9ffee8dfd397 (diff) |
Merge #11646: Require a steady clock for bench with at least micro precision
620bae3 Require a steady clock for bench with at least micro precision (Matt Corallo)
Pull request description:
Using a non-steady high_precision_clock by default is definitely not what we want, and in practice steady_clock has more than enough precision. Should double-check that travis passes on this one to make sure we actually have at least microsecond precision on all platforms.
Tree-SHA512: 54a4af3b6addca9897e8ab04694f9461343691b475ca3ed2368595c37520612e284969be94a8ee3d7c66d16532f7bb16b6ad80284cbc153653e8ef2d56696e9d
-rw-r--r-- | src/bench/bench.cpp | 3 | ||||
-rw-r--r-- | src/bench/bench.h | 6 |
2 files changed, 5 insertions, 4 deletions
diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp index dd4ba5ab0e..4c5a036773 100644 --- a/src/bench/bench.cpp +++ b/src/bench/bench.cpp @@ -23,6 +23,9 @@ void benchmark::BenchRunner::RunAll(benchmark::duration elapsedTimeForOne) { perf_init(); + if (std::ratio_less_equal<benchmark::clock::period, std::micro>::value) { + std::cerr << "WARNING: Clock precision is worse than microsecond - benchmarks may be less accurate!\n"; + } std::cout << "#Benchmark" << "," << "count" << "," << "min(ns)" << "," << "max(ns)" << "," << "average(ns)" << "," << "min_cycles" << "," << "max_cycles" << "," << "average_cycles" << "\n"; diff --git a/src/bench/bench.h b/src/bench/bench.h index d276f4ee91..ab5c3d5604 100644 --- a/src/bench/bench.h +++ b/src/bench/bench.h @@ -37,13 +37,11 @@ BENCHMARK(CODE_TO_TIME); */ namespace benchmark { - // On many systems, the high_resolution_clock offers no better resolution than the steady_clock. - // If that's the case, prefer the steady_clock. + // In case high_resolution_clock is steady, prefer that, otherwise use steady_clock. struct best_clock { using hi_res_clock = std::chrono::high_resolution_clock; using steady_clock = std::chrono::steady_clock; - static constexpr bool steady_is_high_res = std::ratio_less_equal<steady_clock::period, hi_res_clock::period>::value; - using type = std::conditional<steady_is_high_res, steady_clock, hi_res_clock>::type; + using type = std::conditional<hi_res_clock::is_steady, hi_res_clock, steady_clock>::type; }; using clock = best_clock::type; using time_point = clock::time_point; |