start.pthread.m.c 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <sys/time.h>
  4. #include <math.h>
  5. #include <pthread.h>
  6. #define OVERHEAD_TIMES 30000
  7. double my_sqrt(double num)
  8. {
  9. return sqrt(num);
  10. }
  11. pthread_t my_pthread_self(void)
  12. {
  13. return pthread_self();
  14. }
  15. int main (int argc, char ** argv, char ** envp)
  16. {
  17. struct timeval tv;
  18. gettimeofday(&tv, NULL);
  19. if (argc < 2)
  20. return -1;
  21. unsigned long long msec1 = atoll(argv[1]);
  22. unsigned long long msec2 = tv.tv_sec * 1000000ULL + tv.tv_usec;
  23. struct timeval tv1, tv2;
  24. gettimeofday(&tv1, NULL);
  25. for (int j = 0 ; j < OVERHEAD_TIMES ; j++)
  26. gettimeofday(&tv, NULL);
  27. gettimeofday(&tv2, NULL);
  28. unsigned long long msec3 = tv1.tv_sec * 1000000ULL + tv1.tv_usec;
  29. unsigned long long msec4 = tv2.tv_sec * 1000000ULL + tv2.tv_usec;
  30. unsigned long long overhead = (msec4 - msec3) / OVERHEAD_TIMES;
  31. printf("%llu\n", msec2 - msec1 - overhead);
  32. my_sqrt(1.0);
  33. my_sqrt(2.0);
  34. my_pthread_self();
  35. return 0;
  36. }