0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 16:51:22 +08:00

Return current time in nanoseconds

This commit is contained in:
Sergey Yagovtsev 2016-07-31 20:01:02 +03:00
parent 2f833fc0a8
commit 35faba94c9

View File

@ -40,12 +40,12 @@ inline timestamp_t getCurrentTime()
LARGE_INTEGER elapsedMicroseconds; LARGE_INTEGER elapsedMicroseconds;
if (!QueryPerformanceCounter(&elapsedMicroseconds)) if (!QueryPerformanceCounter(&elapsedMicroseconds))
return 0; return 0;
elapsedMicroseconds.QuadPart *= 1000000; elapsedMicroseconds.QuadPart *= 1000000000;
elapsedMicroseconds.QuadPart /= frequency.QuadPart; elapsedMicroseconds.QuadPart /= frequency.QuadPart;
return (timestamp_t)elapsedMicroseconds.QuadPart; return (timestamp_t)elapsedMicroseconds.QuadPart;
#else #else
std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds> time_point; std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_point;
time_point = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()); time_point = std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now());
return time_point.time_since_epoch().count(); return time_point.time_since_epoch().count();
#endif #endif
} }