26#if defined(STAT_BENCH_HAS_WIN_MONOTONE_CLOCK)
32#include <profileapi.h>
43auto win_monotone_clock_frequency() noexcept -> std::int64_t {
47 QueryPerformanceFrequency(&freq);
53 static const double resolution =
54 1.0 /
static_cast<double>(win_monotone_clock_frequency());
55 return Duration(resolution *
static_cast<double>(data_ - right.data_));
62 QueryPerformanceCounter(&ticks);
63 return WinMonotoneTimePoint(ticks.QuadPart);
68 1.0 /
static_cast<double>(win_monotone_clock_frequency());
72WinMonotoneTimePoint::WinMonotoneTimePoint(DataType data) noexcept
80#ifdef STAT_BENCH_HAS_UNIX_MONOTONE_CLOCK
87#define STAT_BENCH_CLOCK_ID CLOCK_MONOTONIC
94 constexpr double nsec_to_sec = 1e-9;
95 return Duration(
static_cast<double>(data_.tv_sec - right.data_.tv_sec) +
96 nsec_to_sec *
static_cast<double>(data_.tv_nsec - right.data_.tv_nsec));
101 if (clock_gettime(STAT_BENCH_CLOCK_ID, &ts) != 0) {
102 std::perror(
"Failed to get the current tick.");
105 return UnixMonotoneTimePoint(ts);
110 if (clock_getres(STAT_BENCH_CLOCK_ID, &ts) != 0) {
111 std::perror(
"Failed to get the resolution of the clock.");
114 constexpr double nsec_to_sec = 1e-9;
115 return Duration(
static_cast<double>(ts.tv_sec) +
116 nsec_to_sec *
static_cast<double>(ts.tv_nsec));
119UnixMonotoneTimePoint::UnixMonotoneTimePoint(DataType data) noexcept
131 const StdMonotoneTimePoint& right)
const noexcept ->
Duration {
132 return Duration(std::chrono::duration_cast<std::chrono::duration<double>>(
138 return StdMonotoneTimePoint(std::chrono::steady_clock::now());
144 static_cast<double>(std::chrono::steady_clock::duration::period::num) /
145 static_cast<double>(std::chrono::steady_clock::duration::period::den));
148StdMonotoneTimePoint::StdMonotoneTimePoint(DataType data) noexcept
auto operator-(const StdMonotoneTimePoint &right) const noexcept -> Duration
Calculate a duration between two time points.
static auto now() noexcept -> StdMonotoneTimePoint
Get the current time from the monotone clock.
static auto resolution() noexcept -> Duration
Get the resolution of the monotone clock.
Class of time points of the monotone clock in Unix.
static auto resolution() noexcept -> Duration
Get the resolution of the monotone clock.
static auto now() noexcept -> UnixMonotoneTimePoint
Get the current time from the monotone clock.
auto operator-(const UnixMonotoneTimePoint &right) const noexcept -> Duration
Calculate a duration between two time points.
Class of time points of the monotone clock in Windows.
static auto resolution() noexcept -> Duration
Get the resolution of the monotone clock.
static auto now() noexcept -> WinMonotoneTimePoint
Get the current time from the monotone clock.
auto operator-(const WinMonotoneTimePoint &right) const noexcept -> Duration
Calculate a duration between two time points.
Definition of Duration class.
Definition of classes of monotone clocks.
Namespace of clocks for benchmarks.
Namespace of stat_bench source codes.