gettimeofday.c 586 B

1234567891011121314151617181920212223242526272829303132
  1. #include <time.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <sys/time.h>
  5. #include <sys/types.h>
  6. #include "osfreq.c"
  7. static double cpufrequency = 0;
  8. static void init(void)
  9. {
  10. cpufrequency = osfreq();
  11. }
  12. long long cpucycles_gettimeofday(void)
  13. {
  14. double result;
  15. struct timeval t;
  16. if (!cpufrequency) init();
  17. gettimeofday(&t,(struct timezone *) 0);
  18. result = t.tv_usec;
  19. result *= 0.000001;
  20. result += (double) t.tv_sec;
  21. result *= cpufrequency;
  22. return result;
  23. }
  24. long long cpucycles_gettimeofday_persecond(void)
  25. {
  26. if (!cpufrequency) init();
  27. return cpufrequency;
  28. }