hiclock.c 561 B

12345678910111213141516171819202122232425
  1. #include "hiclock.h"
  2. #if defined(__WIN32) || defined(__WIN64)
  3. LONGLONG HICLOCKS_PER_SEC = 0;
  4. void hiclock_init() {
  5. LARGE_INTEGER freq;
  6. QueryPerformanceFrequency(&freq);
  7. HICLOCKS_PER_SEC = freq.QuadPart;
  8. }
  9. #endif
  10. hiclock_t hiclock() {
  11. #if defined(__unix__)
  12. timeval clocks;
  13. gettimeofday(&clocks, NULL);
  14. return ((uint64_t)clocks.tv_sec * 1000000ULL) + clocks.tv_usec;
  15. #elif defined(__WIN32) || defined(__WIN64)
  16. LARGE_INTEGER clocks;
  17. QueryPerformanceCounter(&clocks);
  18. return clocks.QuadPart;
  19. #else
  20. return clock();
  21. #endif
  22. }