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

  1. /*******************************************************************************
  2.  *  The BYTE UNIX Benchmarks - Release 2
  3.  *          Module: fstime.c   SID: 2.8 4/17/90 16:45:33
  4.  *          
  5.  *******************************************************************************
  6.  * Bug reports, patches, comments, suggestions should be sent to:
  7.  *
  8.  *    Ben Smith or Rick Grehan at BYTE Magazine
  9.  *    bensmith@bixpb.UUCP    rick_g@bixpb.UUCP
  10.  *
  11.  *******************************************************************************
  12.  *  Modification Log:
  13.  * $Header: fstime.c,v 3.4 87/06/22 14:23:05 kjmcdonell Beta $
  14.  * 10/19/89 - rewrote timing calcs and added clock check (Ben Smith)
  15.  * 10/26/89 - simplify timing, change defaults (Tom Yager)
  16.  * 11/16/89 - added better error handling and changed output format (Ben Smith)
  17.  * 11/17/89 - changed the whole thing around (Ben Smith)
  18.  ******************************************************************************/
  19. char SCCSid[] = "@(#) @(#)fstime.c:2.8 -- 4/17/90 16:45:33";
  20.  
  21. #include <stdio.h>
  22. #include <signal.h>
  23. #include <errno.h>
  24.  
  25. #define SECONDS 10
  26. #define BUFF_SIZE 1024
  27.  
  28. /****************** GLOBALS ***************************/
  29. char buf[BUFF_SIZE];
  30. int            seconds = SECONDS;
  31. int            f;
  32. int            g;
  33. int            i;
  34. int            stop_count();
  35. int            clean_up();
  36. int            sigalarm = 0;
  37.  
  38. /******************** MAIN ****************************/
  39.  
  40. main(argc, argv)
  41. char **argv;
  42. {
  43.  
  44. /**** initialize ****/
  45.     if (argc > 1)
  46.     seconds = atoi(argv[1]);
  47.     if (argc == 3 && chdir(argv[2]) == -1) 
  48.         {
  49.         perror("fstime: chdir");
  50.         exit(1);
  51.         }
  52.     if((f = creat("dummy0", 0600)) != -1)
  53.             close(f);
  54.     else
  55.         {
  56.         perror("fstime: creat");
  57.         exit(1);
  58.         }
  59.     if((g = creat("dummy1", 0600)) != -1)
  60.             close(g);
  61.     else
  62.         {
  63.         perror("fstime: creat");
  64.         exit(1);
  65.         }
  66.     if((f = open("dummy0", 2)) == -1)
  67.         {
  68.         perror("fstime: open");
  69.         exit(1);
  70.         }
  71.     if((g = open("dummy1", 2)) == -1)
  72.         {
  73.         perror("fstime: open");
  74.         exit(1);
  75.         }
  76.     /* fill buffer */
  77.     for (i = 0; i < BUFF_SIZE; i++)
  78.     buf[i] = i & 0177;
  79.     /*** run the tests ****/
  80.     signal(SIGKILL,clean_up);
  81.     if(w_test())
  82.     {
  83.     clean_up();
  84.     exit(1);
  85.     }
  86.     if(r_test())
  87.     {
  88.     clean_up();
  89.     exit(1);
  90.     }
  91.     if(c_test())
  92.     {
  93.     clean_up();
  94.     exit(1);
  95.     }
  96.     clean_up();
  97.     exit(0);
  98. }
  99.  
  100. w_test() 
  101. /* write test */
  102. {
  103.     long n_blocks = 0L;
  104.     extern int sigalarm;
  105.  
  106.     sync();
  107.     sleep(5); /* to insure the sync */
  108.  
  109.     signal(SIGALRM,stop_count);
  110.     sigalarm = 0; /* reset alarm flag */
  111.     alarm(seconds);
  112.     while(!sigalarm)
  113.     {
  114.     if (write(f, buf, BUFF_SIZE) <= 0)
  115.         {
  116.             if (errno != EINTR) {
  117.             perror("fstime: write");
  118.             return(-1);
  119.                 } else stop_count();
  120.         }
  121.     ++ n_blocks;
  122.         }
  123.     /* stop clock */
  124.     fprintf(stderr, "%ld Kbytes/sec write (%d second sample)\n", 
  125.          (long) n_blocks / (long) seconds, seconds);
  126. return(0);
  127. }
  128.  
  129. r_test() 
  130. /* read test */
  131. {
  132.     long n_blocks = 0L;
  133.     extern int sigalarm;
  134.     extern int errno;
  135.  
  136.     /* rewind */
  137.     sync();
  138.     sleep(5);
  139.     lseek(f, 0L, 0);
  140.  
  141.     signal(SIGALRM,stop_count);
  142.     sigalarm = 0; /* reset alarm flag */
  143.     alarm(seconds);
  144.     while(!sigalarm)
  145.     {
  146.     if (read(f, buf, BUFF_SIZE) <= 0)
  147.         {
  148.             if (errno == EINVAL) {
  149.                 lseek(f, 0L, 0);  /* rewind at end of file */
  150.             } else {
  151.                 if (errno != EINTR) {
  152.                    perror("fstime: read");
  153.                return(-1);
  154.                    } else stop_count();
  155.             }
  156.             }
  157.     ++ n_blocks;
  158.         }
  159.     /* stop clock */
  160.     fprintf(stderr, "%ld Kbytes/sec read (%d second sample)\n", 
  161.          (long) n_blocks / (long) seconds, seconds);
  162. return(0);
  163. }
  164.  
  165.  
  166. c_test() 
  167. /* copy test */
  168. {
  169.     long n_blocks = 0L;
  170.     extern int sigalarm;
  171.  
  172.     /* rewind */
  173.     sync();
  174.     sleep(5); /* to insure the sync */
  175.     lseek(f, 0L, 0);
  176.  
  177.     signal(SIGALRM,stop_count);
  178.     sigalarm = 0; /* reset alarm flag */
  179.     alarm(seconds);
  180.     while(!sigalarm)
  181.     {
  182.     if (read(f, buf, BUFF_SIZE) <= 0)
  183.         {
  184.             if (errno == EINVAL) {
  185.                 lseek(f, 0L, 0);  /* rewind at end of file */
  186.             } else {
  187.                 if (errno != EINTR) {
  188.                     perror("fstime: read");
  189.                 return(-1);
  190.                     } else stop_count();
  191.             }
  192.             }
  193.     if (write(g, buf, BUFF_SIZE) <= 0)
  194.         {
  195.             if (errno != EINTR) {
  196.             perror("fstime: write in copy");
  197.             return(-1);
  198.                 } else stop_count();
  199.         }
  200.     ++ n_blocks;
  201.         }
  202.     /* stop clock */
  203.     fprintf(stderr, "%ld Kbytes/sec copy (%d second sample)\n", 
  204.          (long) n_blocks / (long) seconds, seconds);
  205. return(0);
  206. }
  207.  
  208. stop_count()
  209. {
  210. extern int sigalarm;
  211. sigalarm = 1;
  212. return(0);
  213. }
  214.  
  215. clean_up()
  216. {
  217. unlink(f);
  218. unlink(g);
  219. return(0);
  220. }
  221.