NeoPZ
clock_timer.h
Go to the documentation of this file.
1 #ifndef CLOCK_TIMER_H
2 
3 #include<pz_gettime.h>
4 
5 class ClockTimer
6 {
7  public:
8  ClockTimer() {};
9 
10  void start() {
11  gettimeofday(&t1, NULL);
12  }
13 
14  void stop() {
15  timeval t2;
16  gettimeofday(&t2, NULL);
17  elapsed = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms
18  elapsed += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms
19  }
20 
21  double getUnits() {return (double) elapsed;}
22 
23  std::string getTime() {
24  std::string str = double_to_string(elapsed);
25  str += " ms";
26  return str;
27  }
28 
29  private:
30 
31  timeval t1;
32  double elapsed;
33 
34  std::string double_to_string(double dbl) {
35  std::ostringstream strs;
36  strs << dbl;
37  return strs.str();
38  }
39 
40 };
41 
42 #endif
std::string double_to_string(double dbl)
Definition: clock_timer.h:34
std::string getTime()
Definition: clock_timer.h:23
timeval t1
Definition: clock_timer.h:31
double elapsed
Definition: clock_timer.h:32
std::numeric_limits< REAL > dbl
void stop()
Definition: clock_timer.h:14
void start()
Definition: clock_timer.h:10
double getUnits()
Definition: clock_timer.h:21