home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / byteunix.lzh / byte.1 / cctest.c < prev    next >
C/C++ Source or Header  |  1990-05-11  |  4KB  |  154 lines

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