Merge commit '20da8bbe504c0b81f6f3aff5b23f5bc3ee97d3f4' into lite
This commit is contained in:
commit
eb7cccffa4
@ -18,6 +18,7 @@ namespace utils {
|
||||
* \brief return time in seconds, not cross platform, avoid to use this in most places
|
||||
*/
|
||||
inline double GetTime(void) {
|
||||
// TODO: use c++11 chrono when c++11 was available
|
||||
#ifdef __MACH__
|
||||
clock_serv_t cclock;
|
||||
mach_timespec_t mts;
|
||||
@ -26,9 +27,14 @@ inline double GetTime(void) {
|
||||
mach_port_deallocate(mach_task_self(), cclock);
|
||||
return static_cast<double>(mts.tv_sec) + static_cast<double>(mts.tv_nsec) * 1e-9;
|
||||
#else
|
||||
#if defined(__unix__) || defined(__linux__)
|
||||
timespec ts;
|
||||
utils::Check(clock_gettime(CLOCK_REALTIME, &ts) == 0, "failed to get time");
|
||||
return static_cast<double>(ts.tv_sec) + static_cast<double>(ts.tv_nsec) * 1e-9;
|
||||
#else
|
||||
// TODO: add MSVC macro, and MSVC timer
|
||||
return static_cast<double>(time(NULL));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
} // namespace utils
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user