diff --git a/subtree/rabit/include/rabit/timer.h b/subtree/rabit/include/rabit/timer.h index eaada7ef4..46b7affc4 100644 --- a/subtree/rabit/include/rabit/timer.h +++ b/subtree/rabit/include/rabit/timer.h @@ -18,7 +18,8 @@ namespace utils { * \brief return time in seconds, not cross platform, avoid to use this in most places */ inline double GetTime(void) { - #ifdef __MACH__ + // TODO: use c++11 chrono when c++11 was available + #ifdef __MACH__ clock_serv_t cclock; mach_timespec_t mts; host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); @@ -26,9 +27,14 @@ inline double GetTime(void) { mach_port_deallocate(mach_task_self(), cclock); return static_cast(mts.tv_sec) + static_cast(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(ts.tv_sec) + static_cast(ts.tv_nsec) * 1e-9; + #else + // TODO: add MSVC macro, and MSVC timer + return static_cast(time(NULL)); + #endif #endif } } // namespace utils