start.c 968 B

1234567891011121314151617181920212223242526272829303132
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <sys/time.h>
  6. #define OVERHEAD_TIMES 30000
  7. int main (int argc, char ** argv, char ** envp)
  8. {
  9. struct timeval tv;
  10. gettimeofday(&tv, NULL);
  11. if (argc < 2)
  12. return -1;
  13. unsigned long long msec1 = atoll(argv[1]);
  14. unsigned long long msec2 = tv.tv_sec * 1000000ULL + tv.tv_usec;
  15. struct timeval tv1, tv2;
  16. gettimeofday(&tv1, NULL);
  17. for (int j = 0 ; j < OVERHEAD_TIMES ; j++)
  18. gettimeofday(&tv, NULL);
  19. gettimeofday(&tv2, NULL);
  20. unsigned long long msec3 = tv1.tv_sec * 1000000ULL + tv1.tv_usec;
  21. unsigned long long msec4 = tv2.tv_sec * 1000000ULL + tv2.tv_usec;
  22. unsigned long long overhead = (msec4 - msec3) / OVERHEAD_TIMES;
  23. printf("%llu\n", msec2 - msec1 - overhead);
  24. return 0;
  25. }