home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / musbus / part02 / fstime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-16  |  4.3 KB  |  221 lines

  1. /*
  2.  * $Header: fstime.c,v 3.4 87/06/22 14:23:05 kjmcdonell Beta $
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #ifdef SysV
  8. #include <sys/times.h>
  9. #include <sys/param.h>
  10. #ifdef interdata
  11. #define HZ tbuffer.tms_cfreq
  12. #endif
  13. #ifndef HZ
  14.     On your system, what is the value of HZ for high resolution elapsed
  15.     time as returned by times() or its equivalent?
  16. #endif
  17. #endif
  18. #ifdef BSD4v1
  19. #include <sys/timeb.h>
  20. #endif
  21. #ifdef BSD4v2
  22. #include <sys/time.h>
  23. #endif
  24. #define NKBYTE 20
  25. char buf[BUFSIZ];
  26.  
  27. main(argc, argv)
  28. char **argv;
  29. {
  30.     int            n = NKBYTE;
  31.     int            nblock;
  32.     int            f;
  33.     int            g;
  34.     int            i;
  35.     int            xfer, t;
  36.     long        then;
  37. #ifdef BSD4v1
  38.     struct timeb    tbuf;
  39.     int            msec;
  40. #endif
  41. #ifdef BSD4v2
  42.     struct timeval    tval;
  43.     struct timezone    tzone;
  44.     long        usec;
  45. #endif
  46. #ifdef SysV
  47.     struct tms        tbuffer;
  48. #endif
  49.  
  50.     if (argc > 1)
  51.     n = atoi(argv[1]);
  52. #if debug
  53.     printf("File size: %d Kbytes\n", n);
  54. #endif
  55.     nblock = (n * 1024) / BUFSIZ;
  56.  
  57.     if (argc == 3 && chdir(argv[2]) != -1) {
  58. #if debug
  59.     printf("Create files in directory: %s\n", argv[2]);
  60. #endif
  61.     }
  62.     close(creat("dummy0", 0600));
  63.     close(creat("dummy1", 0600));
  64.     f = open("dummy0", 2);
  65.     g = open("dummy1", 2);
  66.     unlink("dummy0");
  67.     unlink("dummy1");
  68.     for (i = 0; i < sizeof(buf); i++)
  69.     buf[i] = i & 0177;
  70.  
  71. #ifdef SysV
  72.     then = times(&tbuffer);
  73. #else
  74. #ifdef BSD4v1
  75.     ftime(&tbuf);
  76.     then = tbuf.time;
  77.     msec = tbuf.millitm;
  78. #else
  79. #ifdef BSD4v2
  80.     gettimeofday(&tval, &tzone);
  81.     then = tval.tv_sec;
  82.     usec = tval.tv_usec;
  83. #else
  84.     What sort of Unix system if this?
  85. #endif
  86. #endif
  87. #endif
  88.     for (i = 0; i < nblock; i++) {
  89.     if (write(f, buf, sizeof(buf)) <= 0)
  90.         perror("fstime: write");
  91.     }
  92. #ifdef SysV
  93.     t = 1000*(times(&tbuffer) - then)/HZ;
  94. #endif
  95. #ifdef BSD4v1
  96.     ftime(&tbuf);
  97.     t = (tbuf.time - then)*1000 + tbuf.millitm - msec;
  98. #endif
  99. #ifdef BSD4v2
  100.     gettimeofday(&tval, &tzone);
  101.     t = (tval.tv_sec - then)*1000 + (tval.tv_usec - usec)/1000;
  102. #endif
  103. #if debug
  104.     printf("Effective write rate: ");
  105. #endif
  106.     if (t > 0) {
  107.     xfer = nblock * sizeof(buf) * 1000 / t;
  108. #if debug
  109.     printf("%d bytes/sec\n", xfer);
  110. #endif
  111.     }
  112. #if debug
  113.     else
  114.     printf(" -- too quick to time!\n");
  115. #endif
  116. #if awk
  117.     fprintf(stderr, "%.2f", t > 0 ? (float)xfer/1024 : 0);
  118. #endif
  119.  
  120.     sync();
  121.     sleep(5);
  122.     sync();
  123.     lseek(f, 0L, 0);
  124. #ifdef SysV
  125.     then = times(&tbuffer);
  126. #endif
  127. #ifdef BSD4v1
  128.     times(&tbuf);
  129.     then = tbuf.time;
  130.     msec = tbuf.millitm;
  131. #endif
  132. #ifdef BSD4v2
  133.     gettimeofday(&tval, &tzone);
  134.     then = tval.tv_sec;
  135.     usec = tval.tv_usec;
  136. #endif
  137.     for (i = 0; i < nblock; i++) {
  138.     if (read(f, buf, sizeof(buf)) <= 0)
  139.         perror("fstime: read");
  140.     }
  141. #ifdef SysV
  142.     t = 1000*(times(&tbuffer) - then)/HZ;
  143. #endif
  144. #ifdef BSD4v1
  145.     ftime(&tbuf);
  146.     t = (tbuf.time - then)*1000 + tbuf.millitm - msec;
  147. #endif
  148. #ifdef BSD4v2
  149.     gettimeofday(&tval, &tzone);
  150.     t = (tval.tv_sec - then)*1000 + (tval.tv_usec - usec)/1000;
  151. #endif
  152. #if debug
  153.     printf("Effective read rate: ");
  154. #endif
  155.     if (t > 0) {
  156.     xfer = nblock * sizeof(buf) * 1000 / t;
  157. #if debug
  158.     printf("%d bytes/sec\n", xfer);
  159. #endif
  160.     }
  161. #if debug
  162.     else
  163.     printf(" -- too quick to time!\n");
  164. #endif
  165. #if awk
  166.     fprintf(stderr, " %.2f", t > 0 ? (float)xfer/1024 : 0);
  167. #endif
  168.  
  169.     sync();
  170.     sleep(5);
  171.     sync();
  172.     lseek(f, 0L, 0);
  173. #ifdef SysV
  174.     then = times(&tbuffer);
  175. #endif
  176. #ifdef BSD4v1
  177.     times(&tbuf);
  178.     then = tbuf.time;
  179.     msec = tbuf.millitm;
  180. #endif
  181. #ifdef BSD4v2
  182.     gettimeofday(&tval, &tzone);
  183.     then = tval.tv_sec;
  184.     usec = tval.tv_usec;
  185. #endif
  186.     for (i = 0; i < nblock; i++) {
  187.     if (read(f, buf, sizeof(buf)) <= 0)
  188.         perror("fstime: read in copy");
  189.     if (write(g, buf, sizeof(buf)) <= 0)
  190.         perror("fstime: write in copy");
  191.     }
  192. #ifdef SysV
  193.     t = 1000*(times(&tbuffer) - then)/HZ;
  194. #endif
  195. #ifdef BSD4v1
  196.     ftime(&tbuf);
  197.     t = (tbuf.time - then)*1000 + tbuf.millitm - msec;
  198. #endif
  199. #ifdef BSD4v2
  200.     gettimeofday(&tval, &tzone);
  201.     t = (tval.tv_sec - then)*1000 + (tval.tv_usec - usec)/1000;
  202. #endif
  203. #if debug
  204.     printf("Effective copy rate: ");
  205. #endif
  206.     if (t > 0) {
  207.     xfer = nblock * sizeof(buf) * 1000 / t;
  208. #if debug
  209.     printf("%d bytes/sec\n", xfer);
  210. #endif
  211.     }
  212. #if debug
  213.     else
  214.     printf(" -- too quick to time!\n");
  215. #endif
  216. #if awk
  217.     fprintf(stderr, " %.2f\n", t > 0 ? (float)xfer/1024 : 0);
  218. #endif
  219.     exit(0);
  220. }
  221.