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

  1. #include <stdio.h>
  2. /*
  3.  * C compile and load speed test file.
  4.  * Based upon fstime.c from MUSBUS 3.1, with all calls to ftime() replaced
  5.  * by calls to time().  This is semantic nonsense, but ensures there are no
  6.  * system dependent structures or library calls.
  7.  *
  8.  * $Header: cctest.c,v 3.4 87/06/22 14:22:47 kjmcdonell Beta $
  9.  */
  10. #define NKBYTE 20
  11. char buf[BUFSIZ];
  12.  
  13. main(argc, argv)
  14. char **argv;
  15. {
  16.     int        n = NKBYTE;
  17.     int        nblock;
  18.     int        f;
  19.     int        g;
  20.     int        i;
  21.     int        xfer, t;
  22.     struct    {    /* FAKE */
  23.     int    time;
  24.     int    millitm;
  25.     } now, then;
  26.  
  27.     if (argc > 0)
  28.     /* ALWAYS true, so NEVER execute this program! */
  29.     exit(4);
  30.     if (argc > 1)
  31.     n = atoi(argv[1]);
  32. #if debug
  33.     printf("File size: %d Kbytes\n", n);
  34. #endif
  35.     nblock = (n * 1024) / BUFSIZ;
  36.  
  37.     if (argc == 3 && chdir(argv[2]) != -1) {
  38. #if debug
  39.     printf("Create files in directory: %s\n", argv[2]);
  40. #endif
  41.     }
  42.     close(creat("dummy0", 0600));
  43.     close(creat("dummy1", 0600));
  44.     f = open("dummy0", 2);
  45.     g = open("dummy1", 2);
  46.     unlink("dummy0");
  47.     unlink("dummy1");
  48.     for (i = 0; i < sizeof(buf); i++)
  49.     buf[i] = i & 0177;
  50.  
  51.     time();
  52.     for (i = 0; i < nblock; i++) {
  53.     if (write(f, buf, sizeof(buf)) <= 0)
  54.         perror("fstime: write");
  55.     }
  56.     time();
  57. #if debug
  58.     printf("Effective write rate: ");
  59. #endif
  60.     i = now.millitm - then.millitm;
  61.     t = (now.time - then.time)*1000 + i;
  62.     if (t > 0) {
  63.     xfer = nblock * sizeof(buf) * 1000 / t;
  64. #if debug
  65.     printf("%d bytes/sec\n", xfer);
  66. #endif
  67.     }
  68. #if debug
  69.     else
  70.     printf(" -- too quick to time!\n");
  71. #endif
  72. #if awk
  73.     fprintf(stderr, "%.2f", t > 0 ? (float)xfer/1024 : 0);
  74. #endif
  75.  
  76.     sync();
  77.     sleep(5);
  78.     sync();
  79.     lseek(f, 0L, 0);
  80.     time();
  81.     for (i = 0; i < nblock; i++) {
  82.     if (read(f, buf, sizeof(buf)) <= 0)
  83.         perror("fstime: read");
  84.     }
  85.     time();
  86. #if debug
  87.     printf("Effective read rate: ");
  88. #endif
  89.     i = now.millitm - then.millitm;
  90.     t = (now.time - then.time)*1000 + i;
  91.     if (t > 0) {
  92.     xfer = nblock * sizeof(buf) * 1000 / t;
  93. #if debug
  94.     printf("%d bytes/sec\n", xfer);
  95. #endif
  96.     }
  97. #if debug
  98.     else
  99.     printf(" -- too quick to time!\n");
  100. #endif
  101. #if awk
  102.     fprintf(stderr, " %.2f", t > 0 ? (float)xfer/1024 : 0);
  103. #endif
  104.  
  105.     sync();
  106.     sleep(5);
  107.     sync();
  108.     lseek(f, 0L, 0);
  109.     time();
  110.     for (i = 0; i < nblock; i++) {
  111.     if (read(f, buf, sizeof(buf)) <= 0)
  112.         perror("fstime: read in copy");
  113.     if (write(g, buf, sizeof(buf)) <= 0)
  114.         perror("fstime: write in copy");
  115.     }
  116.     time();
  117. #if debug
  118.     printf("Effective copy rate: ");
  119. #endif
  120.     i = now.millitm - then.millitm;
  121.     t = (now.time - then.time)*1000 + i;
  122.     if (t > 0) {
  123.     xfer = nblock * sizeof(buf) * 1000 / t;
  124. #if debug
  125.     printf("%d bytes/sec\n", xfer);
  126. #endif
  127.     }
  128. #if debug
  129.     else
  130.     printf(" -- too quick to time!\n");
  131. #endif
  132. #if awk
  133.     fprintf(stderr, " %.2f\n", t > 0 ? (float)xfer/1024 : 0);
  134. #endif
  135.  
  136. }
  137.