start.pthread.m.c 1017 B

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