pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
stopwatch.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_PROFILING_STOPWATCH_H
4#define pRC_CORE_PROFILING_STOPWATCH_H
5
6#include <cstdint>
7
8extern "C"
9{
10#include <time.h>
11}
12#include <prc/core/log/log.hpp>
20
21namespace pRC
22{
24 {
27 {
28 Logging::error("Unable to get current time.");
29 }
30 return static_cast<double>(timeSpec.tv_nsec) / 1e9 + timeSpec.tv_sec;
31 }
32
34 {
35 private:
37 using Float = pRC::Float<64>;
38
39 public:
40 ~Stopwatch() = default;
41 Stopwatch(Stopwatch const &) = delete;
42 Stopwatch(Stopwatch &&) = default;
43 Stopwatch &operator=(Stopwatch const &) = delete;
44 Stopwatch &operator=(Stopwatch &&) & = default;
45
47 : mFlops(flops)
48 , mBytes(bytes)
49 {
50 }
51
52 auto start()
53 {
54 mSeconds -= getTimeInSeconds();
55 mPerfCycles.start();
56 }
57
58 auto stop()
59 {
60 mPerfCycles.stop();
61 mSeconds += getTimeInSeconds();
62 }
63
64 auto reset()
65 {
66 mSeconds = zero();
67 mPerfCycles.reset();
68 mFlops = zero();
69 mBytes = zero();
70 }
71
73 {
74 mFlops += flops;
75 }
76
78 {
79 mBytes += bytes;
80 }
81
82 auto seconds() const
83 {
84 return mSeconds;
85 }
86
87 auto cycles() const
88 {
89 return mPerfCycles.value();
90 }
91
92 auto cyclesPerSecond() const
93 {
94 return cycles() / seconds();
95 }
96
97 auto flops() const
98 {
99 return mFlops;
100 }
101
102 auto flopsPerSecond() const
103 {
104 return flops() / seconds();
105 }
106
107 auto flopsPerCycle() const
108 {
109 return cast<Float>(flops()) / cycles();
110 }
111
112 auto bytes() const
113 {
114 return mBytes;
115 }
116
117 auto bytesPerSecond() const
118 {
119 return bytes() / seconds();
120 }
121
122 auto bytesPerCycle() const
123 {
124 return cast<Float>(bytes()) / cycles();
125 }
126
127 private:
128 Float mSeconds = zero();
130 Integer mFlops;
131 Integer mBytes;
132 };
133}
134#endif // pRC_CORE_PROFILING_STOPWATCH_H
Top-level class storing a floating point number.
Definition float.hpp:35
Definition perfevent.hpp:33
auto start()
Definition perfevent.hpp:107
auto reset()
Definition perfevent.hpp:133
auto stop()
Definition perfevent.hpp:117
auto value() const
Definition perfevent.hpp:142
Top-level class storing a floating point number.
Definition integer.hpp:47
Definition stopwatch.hpp:34
Stopwatch(Stopwatch const &)=delete
auto bytes() const
Definition stopwatch.hpp:112
auto cyclesPerSecond() const
Definition stopwatch.hpp:92
auto cycles() const
Definition stopwatch.hpp:87
Stopwatch(Integer const flops=zero(), Integer const bytes=zero())
Definition stopwatch.hpp:46
auto flopsPerSecond() const
Definition stopwatch.hpp:102
auto seconds() const
Definition stopwatch.hpp:82
auto addFlops(Integer const flops)
Definition stopwatch.hpp:72
auto stop()
Definition stopwatch.hpp:58
auto bytesPerSecond() const
Definition stopwatch.hpp:117
auto flopsPerCycle() const
Definition stopwatch.hpp:107
auto start()
Definition stopwatch.hpp:52
auto reset()
Definition stopwatch.hpp:64
Stopwatch & operator=(Stopwatch &&) &=default
auto bytesPerCycle() const
Definition stopwatch.hpp:122
Stopwatch(Stopwatch &&)=default
~Stopwatch()=default
auto addBytes(Integer const bytes)
Definition stopwatch.hpp:77
auto flops() const
Definition stopwatch.hpp:97
Stopwatch & operator=(Stopwatch const &)=delete
static void error(Xs &&...args)
Definition log.hpp:14
Definition cholesky.hpp:18
static constexpr auto zero()
Definition zero.hpp:12
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
static Float< 64 > getTimeInSeconds()
Definition stopwatch.hpp:23