guanaqo 1.0.0-alpha.24
Utilities for scientific software
Loading...
Searching...
No Matches
timed-cpu.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file
4/// @ingroup timing
5/// CPU and wall-time measurements with RAII helper.
6
7#include <guanaqo/export.h>
8#include <guanaqo/timed.hpp>
9#include <iosfwd>
10
11namespace guanaqo {
12
13/// @addtogroup timing
14/// @{
15
16/// Measures the number of invocations of a specific piece of code and its
17/// run time.
18struct GUANAQO_EXPORT TimingsCPU {
19 int64_t num_invocations{};
20 std::chrono::nanoseconds wall_time{};
21 std::chrono::nanoseconds cpu_time{};
22};
23
24GUANAQO_EXPORT std::ostream &operator<<(std::ostream &, TimingsCPU);
25
26/// RAII class for measuring wall and CPU time.
27template <>
28struct GUANAQO_EXPORT Timed<TimingsCPU> {
30 ~Timed();
31 Timed(const Timed &) = delete;
32 Timed &operator=(const Timed &) = delete;
33
34 private:
35 using clock = std::chrono::steady_clock;
37 clock::time_point wall_start_time;
39};
40
41/// @}
42
43} // namespace guanaqo
std::chrono::nanoseconds wall_time
Definition timed-cpu.hpp:20
std::chrono::nanoseconds cpu_time
Definition timed-cpu.hpp:21
std::ostream & operator<<(std::ostream &, TimingsCPU)
Definition timed-cpu.cpp:31
Measures the number of invocations of a specific piece of code and its run time.
Definition timed-cpu.hpp:18
std::chrono::steady_clock clock
Definition timed-cpu.hpp:35
clock::time_point wall_start_time
Definition timed-cpu.hpp:37
Timed(TimingsCPU &time)
Definition timed-cpu.cpp:44
Timed(const Timed &)=delete
Timed & operator=(const Timed &)=delete
RAII timing helper.