start.c 799 B

1234567891011121314151617181920212223242526272829
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/time.h>
  4. #define OVERHEAD_TIMES 30000
  5. int main(int argc, char** argv, char** envp) {
  6. struct timeval tv;
  7. gettimeofday(&tv, NULL);
  8. if (argc < 2)
  9. return 1;
  10. unsigned long long msec1 = atoll(argv[1]);
  11. unsigned long long msec2 = tv.tv_sec * 1000000ULL + tv.tv_usec;
  12. struct timeval tv1, tv2;
  13. gettimeofday(&tv1, NULL);
  14. for (int j = 0; j < OVERHEAD_TIMES; j++) {
  15. gettimeofday(&tv, NULL);
  16. }
  17. gettimeofday(&tv2, NULL);
  18. unsigned long long msec3 = tv1.tv_sec * 1000000ULL + tv1.tv_usec;
  19. unsigned long long msec4 = tv2.tv_sec * 1000000ULL + tv2.tv_usec;
  20. unsigned long long overhead = (msec4 - msec3) / OVERHEAD_TIMES;
  21. printf("%llu\n", msec2 - msec1 - overhead);
  22. return 0;
  23. }