cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
monotone_time_point.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <chrono>
23
25
26#if defined(STAT_BENCH_DOCUMENTATION)
27#include <cstdint>
28
29#include <time.h>
30#elif defined(_WIN32)
31#define STAT_BENCH_HAS_WIN_MONOTONE_CLOCK 1
32#include <cstdint>
33#elif defined(__unix__)
34#define STAT_BENCH_HAS_UNIX_MONOTONE_CLOCK 1
35#include <time.h> // NOLINT: std::timespec doesn't exist in C++ 14.
36#else
37// No definition here.
38#endif
39
40namespace stat_bench {
41namespace clock {
42
43#if defined(STAT_BENCH_DOCUMENTATION) || \
44 defined(STAT_BENCH_HAS_WIN_MONOTONE_CLOCK)
45
51class WinMonotoneTimePoint {
52public:
59 [[nodiscard]] auto operator-(
60 const WinMonotoneTimePoint& right) const noexcept -> Duration;
61
67 [[nodiscard]] static auto now() noexcept -> WinMonotoneTimePoint;
68
74 [[nodiscard]] static auto resolution() noexcept -> Duration;
75
76private:
78 using DataType = std::int64_t;
79
85 explicit WinMonotoneTimePoint(DataType data) noexcept;
86
88 DataType data_;
89};
90
91#endif
92
93#if defined(STAT_BENCH_DOCUMENTATION) || \
94 defined(STAT_BENCH_HAS_UNIX_MONOTONE_CLOCK)
95
101class UnixMonotoneTimePoint {
102public:
109 [[nodiscard]] auto operator-(
110 const UnixMonotoneTimePoint& right) const noexcept -> Duration;
111
117 [[nodiscard]] static auto now() noexcept -> UnixMonotoneTimePoint;
118
124 [[nodiscard]] static auto resolution() noexcept -> Duration;
125
126private:
128 using DataType = timespec;
129
135 explicit UnixMonotoneTimePoint(DataType data) noexcept;
136
138 DataType data_;
139};
140
141#endif
142
149class StdMonotoneTimePoint {
150public:
157 [[nodiscard]] auto operator-(
158 const StdMonotoneTimePoint& right) const noexcept -> Duration;
159
165 [[nodiscard]] static auto now() noexcept -> StdMonotoneTimePoint;
166
172 [[nodiscard]] static auto resolution() noexcept -> Duration;
173
174private:
176 using DataType = std::chrono::steady_clock::time_point;
177
183 explicit StdMonotoneTimePoint(DataType data) noexcept;
184
186 DataType data_;
187};
188
189#if defined(STAT_BENCH_DOCUMENTATION)
191using MonotoneTimePoint = <platform_dependent_type>;
192#elif defined(STAT_BENCH_HAS_WIN_MONOTONE_CLOCK)
193// Monotone clock in Windows.
195#elif defined(STAT_BENCH_HAS_UNIX_MONOTONE_CLOCK)
196// Monotone clock in Unix.
198#else
199// Fallback using C++ standard library.
201#endif
202
203} // namespace clock
204} // namespace stat_bench
Class of durations.
Definition duration.h:28
Class of time points of the monotone clock in C++ standard library.
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.
Namespace of clocks for benchmarks.
Definition duration.h:23
< platform_dependent_type > MonotoneTimePoint
Type of the monotone clock to use.
Namespace of stat_bench source codes.
STL namespace.