home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / protocol / nfs / 2962 / reader.c next >
Encoding:
C/C++ Source or Header  |  1992-12-15  |  1.1 KB  |  55 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <sys/types.h>
  4. #include <sys/timeb.h>
  5.  
  6. struct timeb timebuffer1;
  7. struct timeb timebuffer2;
  8.  
  9. #define BSIZE 8192
  10. char buf[BSIZE];
  11.  
  12. main(argc, argv)
  13. int argc;
  14. char **argv;
  15. {
  16. int fh;
  17. long total = 0;
  18. long sec;
  19. long msec;
  20. long bpmsec;
  21. int res;
  22. if(argc != 2) {
  23.         printf("usage: %s filename\n", argv[0]);
  24.         exit(1);
  25. }
  26.  
  27. fh = open(argv[1], O_RDONLY|O_BINARY);
  28. if(fh < 0) {
  29.         perror("open:");
  30.         exit(1);
  31. }
  32. ftime(&timebuffer1);
  33. while((res = read(fh, buf, BSIZE)) > 0) total += res;
  34. if(res < 0) {
  35.         perror("read:");
  36.         exit(1);
  37. }
  38. ftime(&timebuffer2);
  39. close(fh);
  40. printf("stop  %10ld.%03d\n", timebuffer2.time, timebuffer2.millitm);
  41. printf("start %10ld.%03d\n", timebuffer1.time, timebuffer1.millitm);
  42.  
  43. sec = timebuffer2.time - timebuffer1.time;
  44. msec = (long)timebuffer2.millitm - (long)timebuffer1.millitm;
  45. if(msec < 0) {
  46.         sec -= 1;
  47.         msec += 1000;
  48. }
  49. msec = sec*1000 + msec;
  50. bpmsec = (msec == 0 ? 0 : total/msec);
  51. printf("total time %ld msec   total bytes %ld   bytes/msec %ld\n",
  52.         msec, total, bpmsec);
  53. exit(0);
  54. }
  55.