Use clock_gettime instead of gettimeofday, it's more effiency on low power system
Add def for mac(They don't support clock_gettime) Fix my mistake Fix my mistake 2
This commit is contained in:
parent
bff230fe2e
commit
797fc14414
|
@ -25,10 +25,14 @@ u32 Timer::GetTimeMs()
|
|||
{
|
||||
#ifdef _WIN32
|
||||
return timeGetTime();
|
||||
#else
|
||||
#elif defined __APPLE__
|
||||
struct timeval t;
|
||||
(void)gettimeofday(&t, nullptr);
|
||||
return ((u32)(t.tv_sec * 1000 + t.tv_usec / 1000));
|
||||
#else
|
||||
struct timespec t;
|
||||
(void)clock_gettime(CLOCK_MONOTONIC, &t);
|
||||
return ((u32)(t.tv_sec * 1000 + t.tv_nsec / 1000000));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -48,10 +52,14 @@ u64 Timer::GetTimeUs()
|
|||
static double freq = GetFreq();
|
||||
QueryPerformanceCounter(&time);
|
||||
return u64(double(time.QuadPart) * freq);
|
||||
#else
|
||||
#elif defined __APPLE__
|
||||
struct timeval t;
|
||||
(void)gettimeofday(&t, nullptr);
|
||||
return ((u64)(t.tv_sec * 1000000 + t.tv_usec));
|
||||
#else
|
||||
struct timespec t;
|
||||
(void)clock_gettime(CLOCK_MONOTONIC, &t);
|
||||
return ((u64)(t.tv_sec * 1000000 + t.tv_nsec / 1000));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -205,10 +213,14 @@ std::string Timer::GetTimeFormatted()
|
|||
struct timeb tp;
|
||||
(void)::ftime(&tp);
|
||||
return StringFromFormat("%s:%03i", tmp, tp.millitm);
|
||||
#else
|
||||
#elif defined __APPLE__
|
||||
struct timeval t;
|
||||
(void)gettimeofday(&t, nullptr);
|
||||
return StringFromFormat("%s:%03d", tmp, (int)(t.tv_usec / 1000));
|
||||
#else
|
||||
struct timespec t;
|
||||
(void)clock_gettime(CLOCK_MONOTONIC, &t);
|
||||
return StringFromFormat("%s:%03d", tmp, (int)(t.tv_nsec / 1000000));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -219,9 +231,12 @@ double Timer::GetDoubleTime()
|
|||
#ifdef _WIN32
|
||||
struct timeb tp;
|
||||
(void)::ftime(&tp);
|
||||
#else
|
||||
#elif defined __APPLE__
|
||||
struct timeval t;
|
||||
(void)gettimeofday(&t, nullptr);
|
||||
#else
|
||||
struct timespec t;
|
||||
(void)clock_gettime(CLOCK_MONOTONIC, &t);
|
||||
#endif
|
||||
// Get continuous timestamp
|
||||
u64 TmpSeconds = Common::Timer::GetTimeSinceJan1970();
|
||||
|
@ -236,8 +251,10 @@ double Timer::GetDoubleTime()
|
|||
u32 Seconds = (u32)TmpSeconds;
|
||||
#ifdef _WIN32
|
||||
double ms = tp.millitm / 1000.0 / 1000.0;
|
||||
#else
|
||||
#elif defined __APPLE__
|
||||
double ms = t.tv_usec / 1000000.0;
|
||||
#else
|
||||
double ms = t.tv_nsec / 1000000000.0;
|
||||
#endif
|
||||
double TmpTime = Seconds + ms;
|
||||
|
||||
|
|
Loading…
Reference in New Issue