6 #ifndef LOFAR_COMMON_TIMER_H
7 #define LOFAR_COMMON_TIMER_H
16 #if defined __ia64__ && defined __INTEL_COMPILER
41 template <
class Clock>
46 explicit BaseTimer(
const std::string& name = std::string())
47 : name_(name), count_(0), duration_(std::chrono::seconds{0}) {}
50 void start() { start_ = Clock::now(); }
53 duration_ += Clock::now() - start_;
60 duration_ = std::chrono::seconds{0};
64 std::ostream&
print(std::ostream& str)
const {
68 str << std::left << std::setw(25) << name_ <<
": " << std::right;
77 <<
", count = " << std::setw(9) << count_;
85 return std::chrono::duration<double>{duration_}.count();
96 duration_ += other.duration_;
97 count_ += other.count_;
123 typename Clock::duration duration_;
126 typename Clock::time_point start_;
145 template <
class T,
class Clock = std::chrono::steady_clock>
146 #if __cplusplus > 201703L
147 requires requires(T& t,
double d) {
154 : accumulator_(accumulator) {
161 accumulator_ += timer_.getElapsed() * 1e6;
Internal class to do an automatic start/stop.
Definition: Timer.h:103
StartStop(BaseTimer< Clock > &timer)
Definition: Timer.h:105
~StartStop()
Definition: Timer.h:106
StartStop & operator=(const StartStop &)=delete
StartStop(const StartStop &)=delete
Forbid copy.
Very accurate timer for elapsed times.
Definition: Timer.h:42
std::ostream & print(std::ostream &str) const
Prints the timer.
Definition: Timer.h:64
void start()
Starts the timer.
Definition: Timer.h:50
double getElapsed() const
Get the elapsed time (in seconds).
Definition: Timer.h:84
uint64_t getCount() const
Get the total number of times start/stop is done.
Definition: Timer.h:92
BaseTimer(const std::string &name=std::string())
Definition: Timer.h:46
BaseTimer & operator+=(const BaseTimer &other)
Accumulate timer statistics.
Definition: Timer.h:95
double getAverage() const
Get the average time (in seconds) between start/stop.
Definition: Timer.h:89
void reset()
Resets the timer to zero.
Definition: Timer.h:58
void stop()
Stops the timer.
Definition: Timer.h:52
Print time in a human-readable way.
Definition: PrettyUnits.h:21
ScopedMicroSecondAccumulator(T &accumulator)
Definition: Timer.h:153
~ScopedMicroSecondAccumulator()
Definition: Timer.h:159
ScopedMicroSecondAccumulator(const ScopedMicroSecondAccumulator &)=delete
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53