home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / protocol / nfs / 2962 / writer.c < prev   
Encoding:
C/C++ Source or Header  |  1992-12-15  |  1.2 KB  |  61 lines

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