HighResolutionTimer.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //////////////////////////////////////////////////////////////////////////////
  2. // Timer.h
  3. // =======
  4. // High Resolution Timer.
  5. // This timer is able to measure the elapsed time with 1 micro-second accuracy
  6. // in both Windows, Linux and Unix system
  7. //
  8. // AUTHOR: Song Ho Ahn ([email protected])
  9. // CREATED: 2003-01-13
  10. // UPDATED: 2006-01-13
  11. //
  12. // Copyright (c) 2003 Song Ho Ahn
  13. //////////////////////////////////////////////////////////////////////////////
  14. #ifndef HIGH_RESOLUTION_TIMER_H_DEF
  15. #define HIGH_RESOLUTION_TIMER_H_DEF
  16. #ifdef WIN32 // Windows system specific
  17. #include <windows.h>
  18. #else // Unix based system specific
  19. #include <sys/time.h>
  20. #endif
  21. class HighResolutionTimer
  22. {
  23. public:
  24. HighResolutionTimer(); // default constructor
  25. ~HighResolutionTimer(); // default destructor
  26. void start(); // start timer
  27. void stop(); // stop the timer
  28. double getElapsedTime(); // get elapsed time in second
  29. double getElapsedTimeInSec(); // get elapsed time in second (same as getElapsedTime)
  30. double getElapsedTimeInMilliSec(); // get elapsed time in milli-second
  31. double getElapsedTimeInMicroSec(); // get elapsed time in micro-second
  32. protected:
  33. private:
  34. double startTimeInMicroSec; // starting time in micro-second
  35. double endTimeInMicroSec; // ending time in micro-second
  36. int stopped; // stop flag
  37. #ifdef WIN32
  38. LARGE_INTEGER frequency; // ticks per second
  39. LARGE_INTEGER startCount; //
  40. LARGE_INTEGER endCount; //
  41. #else
  42. timeval startCount; //
  43. timeval endCount; //
  44. #endif
  45. };
  46. #endif // HIGH_RESOLUTION_TIMER_H_DEF