Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<time.h>
  3. #include <sys/time.h>
  4. #include <sys/resource.h>
  5. int main(int argc, char** argv)
  6. {
  7. struct timeval tv;
  8. struct timezone tz;
  9. int i,delay,num_iter;
  10. double init,start,stop;
  11. if (argc!=3)
  12. {
  13. fprintf(stderr, "Usage: %s <sleep time..msec><num_iteration>\n", argv[0]);
  14. exit(1);
  15. }
  16. // progname=argv[0];
  17. delay=atoi(argv[1]);
  18. num_iter=atoi(argv[2]);
  19.  
  20. printf("Delay is %d..num_iter is %d\n",delay,num_iter);
  21. gettimeofday( &tv,&tz);
  22. init=tv.tv_sec + tv.tv_usec*0.000001;
  23. for(i=0;i<num_iter;++i)
  24. {
  25. gettimeofday( &tv,&tz);
  26. start=tv.tv_sec + tv.tv_usec*0.000001;
  27. // Now sleep
  28. usleep(delay*1000);
  29. gettimeofday( &tv,&tz);
  30. stop=tv.tv_sec + tv.tv_usec*0.000001;
  31. printf("Time is %ld : %ld..slept for %lf ms\n",tv.tv_sec,tv.tv_usec,(stopstart)*1000);
  32. }
  33. printf("Total time taken : actual %lf theory(excl. runtime): %d, ms
  34. \n",(stopinit)*1000,num_iter*delay);
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement