system_time.cpp 620 B

12345678910111213141516171819202122232425262728293031
  1. #include "system_time.h"
  2. #include <Windows.h>
  3. namespace am {
  4. static bool got_clockfreq = false;
  5. static LARGE_INTEGER clock_freq;
  6. static uint64_t get_clockfreq()
  7. {
  8. if (!got_clockfreq) {
  9. QueryPerformanceFrequency(&clock_freq);
  10. got_clockfreq = true;
  11. }
  12. return clock_freq.QuadPart;
  13. }
  14. uint64_t system_time::get_time_ns()
  15. {
  16. LARGE_INTEGER current_time;
  17. double time_val;
  18. QueryPerformanceCounter(&current_time);
  19. time_val = (double) current_time.QuadPart;
  20. time_val *= 1000000000.0;
  21. time_val /= (double) get_clockfreq();
  22. return (uint64_t) time_val;
  23. }
  24. } // namespace am