LocARNA-2.0.0
stopwatch.hh
1 #ifndef LOCARNA_STOPWATCH_HH
2 #define LOCARNA_STOPWATCH_HH
3 
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 #include "aux.hh"
9 #include <iosfwd>
10 #include <unordered_map>
11 #include <string>
12 
13 namespace LocARNA {
17  class StopWatch {
18  private:
19  struct timer_t {
20  bool running;
21  double last_start;
22  double total;
23  size_t cycles;
24 
25  timer_t()
26  : running(false), last_start(0.0), total(0.0), cycles(0) {}
27  };
28 
30  typedef std::unordered_map<std::string, timer_t> map_t;
31 
32  map_t timers;
33 
34  bool print_on_exit;
35 
36  public:
42  explicit StopWatch(bool print_on_exit = false);
43 
47  ~StopWatch();
48 
54  void
55  set_print_on_exit(bool print_on_exit);
56 
64  bool
65  start(const std::string &name);
66 
74  bool
75  stop(const std::string &name);
76 
84  bool
85  is_running(const std::string &name) const;
86 
94  double
95  current_total(const std::string &name) const;
96 
104  size_t
105  current_cycles(const std::string &name) const;
106 
117  std::ostream &
118  print_info(std::ostream &out, const std::string &name) const;
119 
127  std::ostream &
128  print_info(std::ostream &out) const;
129 
130  private:
131  double
132  current_time() const;
133  };
134 }
135 #endif
control a set of named stop watch like timers
Definition: stopwatch.hh:17
StopWatch(bool print_on_exit=false)
Constructor.
Definition: stopwatch.cc:11
void set_print_on_exit(bool print_on_exit)
Definition: stopwatch.cc:20
bool is_running(const std::string &name) const
test whether named timer is running
Definition: stopwatch.cc:54
bool start(const std::string &name)
start a named timer
Definition: stopwatch.cc:25
double current_total(const std::string &name) const
current total time of a named timer
Definition: stopwatch.cc:62
~StopWatch()
Destructor.
Definition: stopwatch.cc:13
bool stop(const std::string &name)
stop a named timer
Definition: stopwatch.cc:38
size_t current_cycles(const std::string &name) const
current start/stop cycles of a named timer
Definition: stopwatch.cc:70
std::ostream & print_info(std::ostream &out, const std::string &name) const
print information for one timer
Definition: stopwatch.cc:78
Definition: aligner.cc:15