PSCF v1.1
Timer.h
1#ifndef UTIL_TIMER_H
2#define UTIL_TIMER_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/global.h>
12
13#ifdef UTIL_CXX11
14#include <chrono>
15#else
16#include <ctime>
17#endif
18
19namespace Util
20{
21
34 class Timer
35 {
36
37 public:
38
39 #ifdef UTIL_CXX11
40 using Clock = std::chrono::steady_clock;
41 using TimePoint = Clock::time_point;
42 #else
43 typedef clock_t TimePoint;
44 #endif
45
49 Timer();
50
58 void start(TimePoint begin);
59
65 void start();
66
72 void stop(TimePoint end);
73
79 void stop();
80
84 bool isRunning();
85
89 void clear();
90
94 double time();
95
99 static TimePoint now();
100
101 private:
102
103 #ifdef UTIL_CXX11
104 using Duration = std::chrono::duration<double>;
105 #else
106 typedef double Duration;
107 #endif
108
110 Duration time_;
111
113 TimePoint begin_;
114
116 bool isRunning_;
117
118 };
119
120 /*
121 * Stop the timer.
122 */
123 inline void Timer::stop()
124 { stop(Timer::now()); }
125
126 /*
127 * Is this timer running?
128 */
129 inline bool Timer::isRunning()
130 { return isRunning_; }
131
132}
133#endif
Wall clock timer.
Definition: Timer.h:35
bool isRunning()
Is this Timer running?
Definition: Timer.h:129
Timer()
Default constructor.
Definition: Timer.cpp:30
void stop()
Stop the clock now (internally supplied).
Definition: Timer.h:123
void start()
Start timing from now (internally computed).
Definition: Timer.cpp:61
void clear()
Reset accumulated time to zero.
Definition: Timer.cpp:89
static TimePoint now()
Return current time point.
Definition: Timer.cpp:18
double time()
Return the accumulated time, in seconds.
Definition: Timer.cpp:37
File containing preprocessor macros for error handling.
Utility classes for scientific computation.
Definition: accumulators.mod:1