hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Timer.h
Go to the documentation of this file.
1 #ifndef TIMER_H
2 #define TIMER_H
3 #include <sys/time.h>
4 class Timer
5 {
6  public:
7  void start()
8  {
9  gettimeofday(&tv, NULL);
10  startUs = tv.tv_usec;
11  startSec = tv.tv_sec;
12  }
13  void stop()
14  {
15  gettimeofday(&tv, NULL);
16  stopUs = tv.tv_usec;
17  stopSec = tv.tv_sec;
18  }
19  double time()
20  {
21  time_t deltaSec = stopSec - startSec;
22  suseconds_t deltaUsec = stopUs - startUs;
23  if(deltaUsec < 0)
24  {
25  deltaSec--;
26  deltaUsec += 1000000;
27  }
28  return double(deltaSec) + double(deltaUsec)/1000000.0;
29  }
30  u_int64_t utime()
31  {
32  time_t deltaSec = stopSec - startSec;
33  suseconds_t deltaUsec = stopUs - startUs;
34  if(deltaUsec < 0)
35  {
36  deltaSec--;
37  deltaUsec += 1000000;
38  }
39  return u_int64_t(deltaSec) * 1000000ull + deltaUsec;
40  }
41  private:
42  struct timeval tv;
43  time_t startSec, stopSec;
44  suseconds_t startUs, stopUs;
45 };
46 #endif