Guest User

Untitled

a guest
Apr 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #ifndef TIMER_H_
  2. #define TIMER_H_
  3.  
  4. #include <sys/time.h>
  5.  
  6. struct Timer
  7. {
  8.     timeval start_time;
  9.  
  10.     // starts the timer
  11.     void start()
  12.     {
  13.         gettimeofday(&start_time, NULL);
  14.     };
  15.  
  16.     // returns how long it has been since the timer was last started in microseconds
  17.     double getTime()
  18.     {
  19.         timeval current_time;
  20.         gettimeofday(&current_time, NULL);
  21.         return (current_time.tv_sec - start_time.tv_sec) * 1000.0
  22.             + (current_time.tv_usec - start_time.tv_usec) / 1000.0;
  23.     };
  24. };
  25.  
  26. #endif //TIMER_H_
Add Comment
Please, Sign In to add comment