MachineIntelligenceCore:Algorithms
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Timer.hpp
Go to the documentation of this file.
1 
23 #ifndef SRC_DATA_UTILS_TIMER_HPP_
24 #define SRC_DATA_UTILS_TIMER_HPP_
25 
26 namespace mic {
27 namespace utils {
28 
33 class Timer {
34 
35  public:
36 
37  Timer() = default;
38  ~Timer() = default;
39 
40  void start(void) {
41 
42  gettimeofday(&s, NULL);
43  }
44 
45  double end(void) {
46 
47  struct timeval diff_tv;
48  gettimeofday(&e, NULL);
49 
50  diff_tv.tv_usec = e.tv_usec - s.tv_usec;
51  diff_tv.tv_sec = e.tv_sec - s.tv_sec;
52 
53  if (s.tv_usec > e.tv_usec) {
54  diff_tv.tv_usec += 1000000;
55  diff_tv.tv_sec--;
56  }
57 
58  return (double) diff_tv.tv_sec + ( (double) diff_tv.tv_usec / 1000000.0);
59 
60  }
61 
62  protected:
63 
64  struct timeval s;
65  struct timeval e;
66 };
67 
68 }//: namespace utils
69 }//: namespace mic
70 
71 
72 #endif /* SRC_DATA_UTILS_TIMER_HPP_ */
void start(void)
Definition: Timer.hpp:40
struct timeval e
Definition: Timer.hpp:65
double end(void)
Definition: Timer.hpp:45
Timer class.
Definition: Timer.hpp:33
struct timeval s
Definition: Timer.hpp:64