aboutsummaryrefslogtreecommitdiff
path: root/src/bench/bench.h
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2017-10-25 17:54:05 -0400
committerCory Fields <cory-nospam-@coryfields.com>2017-11-07 17:17:34 -0500
commit24a0bddf4ae13d8f1fa0436a547de67dcf6d4f2a (patch)
tree750eb10d5a83e928c2afb9ad3e68623f1f4f8809 /src/bench/bench.h
parentc515d266ec04d7f0b2b1b3815a793c27ddcd4e1c (diff)
downloadbitcoin-24a0bddf4ae13d8f1fa0436a547de67dcf6d4f2a.tar.xz
bench: prefer a steady clock if the resolution is no worse
Diffstat (limited to 'src/bench/bench.h')
-rw-r--r--src/bench/bench.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/bench/bench.h b/src/bench/bench.h
index d7037e1f33..d276f4ee91 100644
--- a/src/bench/bench.h
+++ b/src/bench/bench.h
@@ -37,8 +37,15 @@ BENCHMARK(CODE_TO_TIME);
*/
namespace benchmark {
-
- using clock = std::chrono::high_resolution_clock;
+ // On many systems, the high_resolution_clock offers no better resolution than the steady_clock.
+ // If that's the case, prefer the 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 clock = best_clock::type;
using time_point = clock::time_point;
using duration = clock::duration;