LocARNA-1.8.11
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 <string>
11 
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(): running(false), last_start(0.0), total(0.0), cycles(0) {}
26  };
27 
30 
31  map_t timers;
32 
33  bool print_on_exit;
34 
35  public:
36 
42  explicit
43  StopWatch(bool print_on_exit=false);
44 
45 
49  ~StopWatch();
50 
56  void
57  set_print_on_exit(bool print_on_exit);
58 
66  bool
67  start(const std::string &name);
68 
76  bool
77  stop(const std::string &name);
78 
86  bool
87  is_running(const std::string &name) const;
88 
96  double
97  current_total(const std::string &name) const;
98 
106  size_t current_cycles(const std::string &name) const;
107 
118  std::ostream &
119  print_info(std::ostream &out,const std::string &name) const;
120 
128  std::ostream &
129  print_info(std::ostream &out) const;
130 
131 
132  private:
133  double current_time () const;
134  };
135 }
136 #endif
StopWatch(bool print_on_exit=false)
Constructor.
Definition: stopwatch.cc:13
bool stop(const std::string &name)
stop a named timer
Definition: stopwatch.cc:40
Definition: aligner.cc:17
std::ostream & print_info(std::ostream &out, const std::string &name) const
print information for one timer
Definition: stopwatch.cc:84
~StopWatch()
Destructor.
Definition: stopwatch.cc:16
bool start(const std::string &name)
start a named timer
Definition: stopwatch.cc:28
bool is_running(const std::string &name) const
test whether named timer is running
Definition: stopwatch.cc:55
void set_print_on_exit(bool print_on_exit)
Definition: stopwatch.cc:23
size_t current_cycles(const std::string &name) const
current start/stop cycles of a named timer
Definition: stopwatch.cc:73
double current_total(const std::string &name) const
current total time of a named timer
Definition: stopwatch.cc:63
Definition: aux.hh:51
control a set of named stop watch like timers
Definition: stopwatch.hh:17