BsTimerImp.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include "../BsPrerequisitesUtil.h"
  3. #ifndef WIN32_LEAN_AND_MEAN
  4. # define WIN32_LEAN_AND_MEAN
  5. #endif
  6. #if !defined(NOMINMAX) && defined(_MSC_VER)
  7. # define NOMINMAX // Required to stop windows.h messing up std::min
  8. #endif
  9. #include "windows.h"
  10. namespace BansheeEngine
  11. {
  12. /**
  13. * @brief Timer class used for querying high precision timers.
  14. *
  15. * @note Not thread safe.
  16. */
  17. class BS_UTILITY_EXPORT Timer
  18. {
  19. public:
  20. /**
  21. * @brief Construct the timer and start timing.
  22. */
  23. Timer();
  24. ~Timer();
  25. /**
  26. * @brief Reset the timer to zero.
  27. */
  28. void reset();
  29. /**
  30. * @brief Returns time in milliseconds since timer was initialized or
  31. * last reset.
  32. */
  33. unsigned long getMilliseconds();
  34. /**
  35. * @brief Returns time in microseconds since timer was initialized or
  36. * last reset.
  37. */
  38. unsigned long getMicroseconds();
  39. /**
  40. * @brief Returns time in milliseconds since timer was initialized or
  41. * last reset. Only CPU timer measured.
  42. */
  43. unsigned long getMillisecondsCPU();
  44. /**
  45. * @brief Returns time in microseconds since timer was initialized or
  46. * last reset. Only CPU timer measured.
  47. */
  48. unsigned long getMicrosecondsCPU();
  49. /**
  50. * @brief Returns the time at which the timer was initialized, in milliseconds.
  51. *
  52. * @return Time in milliseconds.
  53. */
  54. unsigned long getStartMs() const;
  55. private:
  56. clock_t mZeroClock;
  57. LARGE_INTEGER mStartTime;
  58. LARGE_INTEGER mFrequency;
  59. };
  60. }