CosmoGRaPH v0.0
Timer.h
1 #ifndef COSMO_UTILS_TIMER_H
2 #define COSMO_UTILS_TIMER_H
3 
4 #include <ctime>
5 #include <iostream>
6 #include <map>
7 
8 namespace cosmo
9 {
10 
14 class Timer
15 {
16 public:
17  Timer() : m_secs(0) {}
18 
19  inline double time() const { return m_secs; }
20 
21  inline void start() { clock_gettime(CLOCK_MONOTONIC, &m_starttime); }
22  void stop();
23  void reset();
24 
25  Timer operator+(const Timer &t2);
26  Timer operator-(const Timer &t2);
27 
28 private:
29  double m_secs;
30  struct timespec m_starttime;
31  struct timespec m_stoptime;
32 };
33 
39 {
40 public:
41  TimerManager() {};
42 
43  std::string getStateString();
44 
45  inline Timer& operator[](std::string key) { return m_timers[key]; }
46 
47  friend std::ostream& operator<<(std::ostream &ostr, TimerManager T);
48 
49 private:
50  std::map<std::string, Timer> m_timers;
51 };
52 
53 }
54 
55 #endif
Individual timer classes used by the TimerManager class.
Definition: Timer.h:14
Definition: bardeen.cc:5
void stop()
Stop timer.
Definition: Timer.cc:26
TimerManager class containing multiple timers; access individual timers via, eg, TM["my_timer"].start()
Definition: Timer.h:38
void reset()
Reset timer.
Definition: Timer.cc:36