BsTimer.cpp 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Utility/BsTimer.h"
  4. #include "Utility/BsBitwise.h"
  5. #include <chrono>
  6. using namespace std::chrono;
  7. namespace bs
  8. {
  9. Timer::Timer()
  10. {
  11. reset();
  12. }
  13. void Timer::reset()
  14. {
  15. mStartTime = mHRClock.now();
  16. }
  17. UINT64 Timer::getMilliseconds() const
  18. {
  19. auto newTime = mHRClock.now();
  20. duration<double> dur = newTime - mStartTime;
  21. return duration_cast<milliseconds>(dur).count();
  22. }
  23. UINT64 Timer::getMicroseconds() const
  24. {
  25. auto newTime = mHRClock.now();
  26. duration<double> dur = newTime - mStartTime;
  27. return duration_cast<microseconds>(dur).count();
  28. }
  29. UINT64 Timer::getStartMs() const
  30. {
  31. nanoseconds startTimeNs = mStartTime.time_since_epoch();
  32. return duration_cast<milliseconds>(startTimeNs).count();
  33. }
  34. }