20 #if defined(ION_PLATFORM_WINDOWS)
31 #if defined(ION_PLATFORM_WINDOWS)
32 Timer::steady_clock::time_point Timer::steady_clock::now() {
40 static std::atomic<int64> s_freq;
43 int64 freq = s_freq.load(std::memory_order_relaxed);
45 LARGE_INTEGER li_freq;
46 QueryPerformanceFrequency(&li_freq);
47 freq = li_freq.QuadPart;
50 s_freq.store(freq, std::memory_order_relaxed);
54 QueryPerformanceCounter(&pc);
55 const int64 counter = pc.QuadPart;
56 const int64 sec = (counter / freq) * period::den / period::num;
57 const int64 nano = (counter % freq) * period::den / freq / period::num;
58 return time_point(duration(sec + nano));
75 const int millis =
static_cast<int>(milliseconds);
76 const struct timespec sleeptime = {millis / 1000, (millis % 1000) * 1000000};
77 struct timespec remaining = {0, 0};
78 nanosleep(&sleeptime, &remaining);
85 Timer::Clock::duration
Timer::Get()
const {
return Clock::now() - start_; }
88 return std::chrono::duration_cast<std::chrono::duration<double>>(
Get())
93 return std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(
double GetInS() const
Returns the elapsed time since construction or the last Reset() in seconds.
double GetInMs() const
Returns the elapsed time since construction or the last Reset() in milliseconds.
static void SleepNSeconds(unsigned int seconds)
Sleeps for the passed number of seconds.
static void SleepNMilliseconds(unsigned int milliseconds)
Sleeps for n milliseconds.
void Reset()
Resets the timer.
Clock::duration Get() const
Returns the elapsed time since construction or the last Reset().