| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
|---|---|
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #include "Utility/BsTimer.h" |
| 4 | #include "Utility/BsBitwise.h" |
| 5 | |
| 6 | #include <chrono> |
| 7 | |
| 8 | using namespace std::chrono; |
| 9 | |
| 10 | namespace bs |
| 11 | { |
| 12 | Timer::Timer() |
| 13 | { |
| 14 | reset(); |
| 15 | } |
| 16 | |
| 17 | void Timer::reset() |
| 18 | { |
| 19 | mStartTime = mHRClock.now(); |
| 20 | } |
| 21 | |
| 22 | UINT64 Timer::getMilliseconds() const |
| 23 | { |
| 24 | auto newTime = mHRClock.now(); |
| 25 | duration<double> dur = newTime - mStartTime; |
| 26 | |
| 27 | return duration_cast<milliseconds>(dur).count(); |
| 28 | } |
| 29 | |
| 30 | UINT64 Timer::getMicroseconds() const |
| 31 | { |
| 32 | auto newTime = mHRClock.now(); |
| 33 | duration<double> dur = newTime - mStartTime; |
| 34 | |
| 35 | return duration_cast<microseconds>(dur).count(); |
| 36 | } |
| 37 | |
| 38 | UINT64 Timer::getStartMs() const |
| 39 | { |
| 40 | nanoseconds startTimeNs = mStartTime.time_since_epoch(); |
| 41 | |
| 42 | return duration_cast<milliseconds>(startTimeNs).count(); |
| 43 | } |
| 44 | } |
| 45 |