You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

5 years ago
  1. #pragma once
  2. #include <windows.h>
  3. namespace CELL
  4. {
  5. class CELLTimestamp
  6. {
  7. public:
  8. CELLTimestamp()
  9. {
  10. QueryPerformanceFrequency(&_frequency);
  11. QueryPerformanceCounter(&_startCount);
  12. }
  13. ~CELLTimestamp()
  14. {}
  15. void update()
  16. {
  17. QueryPerformanceCounter(&_startCount);
  18. }
  19. /**
  20. * ȡǰ
  21. */
  22. double getElapsedSecond()
  23. {
  24. return getElapsedTimeInMicroSec() * 0.000001;
  25. }
  26. /**
  27. * ȡ
  28. */
  29. double getElapsedTimeInMilliSec()
  30. {
  31. return this->getElapsedTimeInMicroSec() * 0.001;
  32. }
  33. /**
  34. * ȡ΢
  35. */
  36. double getElapsedTimeInMicroSec()
  37. {
  38. LARGE_INTEGER endCount;
  39. QueryPerformanceCounter(&endCount);
  40. double startTimeInMicroSec = _startCount.QuadPart * (1000000.0 / _frequency.QuadPart);
  41. double endTimeInMicroSec = endCount.QuadPart * (1000000.0 / _frequency.QuadPart);
  42. return endTimeInMicroSec - startTimeInMicroSec;
  43. }
  44. protected:
  45. LARGE_INTEGER _frequency;
  46. LARGE_INTEGER _startCount;
  47. };
  48. }