system_time.cpp 580 B

1234567891011121314151617181920212223242526272829303132
  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. if (!got_clockfreq) {
  8. QueryPerformanceFrequency(&clock_freq);
  9. got_clockfreq = true;
  10. }
  11. return clock_freq.QuadPart;
  12. }
  13. uint64_t system_time::get_time_ns()
  14. {
  15. LARGE_INTEGER current_time;
  16. double time_val;
  17. QueryPerformanceCounter(&current_time);
  18. time_val = (double)current_time.QuadPart;
  19. time_val *= 1000000000.0;
  20. time_val /= (double)get_clockfreq();
  21. return (uint64_t)time_val;
  22. }
  23. }