batmat 0.0.18
Batched linear algebra routines
Loading...
Searching...
No Matches
timing.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <batmat/config.hpp>
4#include <batmat/export.h>
5#include <guanaqo/timed.hpp>
6#if BATMAT_WITH_CPU_TIME
7#include <guanaqo/timed-cpu.hpp>
8#else
9#include <chrono>
10#endif
11
12namespace batmat {
13
14#if BATMAT_WITH_CPU_TIME // TODO
15using DefaultTimings = guanaqo::TimingsCPU;
16#else
17/// Measures the number of invocations of a specific piece of code and its
18/// run time.
19/// @todo Move to guanaqo.
20struct BATMAT_EXPORT DefaultTimings {
21 int64_t num_invocations{};
22 std::chrono::nanoseconds wall_time{};
23};
24
25BATMAT_EXPORT std::ostream &operator<<(std::ostream &, DefaultTimings);
26
27#endif
28
29using guanaqo::timed;
30
31} // namespace batmat
32
33#if !BATMAT_WITH_CPU_TIME
34
35namespace guanaqo {
36
37/// RAII class for measuring wall time.
38template <>
39struct BATMAT_EXPORT Timed<batmat::DefaultTimings> {
42 auto wall_end_time = clock::now();
43 ++time.num_invocations;
44 time.wall_time += wall_end_time - wall_start_time;
45 }
46 Timed(const Timed &) = delete;
47 Timed &operator=(const Timed &) = delete;
48
49 private:
50 using clock = std::chrono::steady_clock;
52 clock::time_point wall_start_time;
53};
54
55} // namespace guanaqo
56
57#endif
decltype(auto) timed(T &time, F &&func, Args &&...args)
std::ostream & operator<<(std::ostream &, DefaultTimings)
Definition timing.cpp:8
std::chrono::nanoseconds wall_time
Definition timing.hpp:22
Measures the number of invocations of a specific piece of code and its run time.
Definition timing.hpp:20
Timed(batmat::DefaultTimings &time)
Definition timing.hpp:40
batmat::DefaultTimings & time
Definition timing.hpp:51
std::chrono::steady_clock clock
Definition timing.hpp:50
Timed & operator=(const Timed &)=delete