home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / FSPERF.ZIP / FSPERF.C next >
Text File  |  1990-06-25  |  11KB  |  264 lines

  1. #define LINT_ARGS 1
  2. #define TESTCOUNT1      8192
  3. #define TESTCOUNT2      2048
  4.  
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <time.h>
  8. #include <fcntl.h>
  9. #include <io.h>
  10. #include <memory.h>
  11. #include <math.h>
  12. #include <float.h>
  13. #include <sys\types.h>
  14. #include <sys\stat.h>
  15.                           
  16.  
  17. char          filename[ ] = "FSPERF.DAT";
  18. char          fbuffer[2048];
  19. unsigned long fpos[TESTCOUNT1];
  20.  
  21. main ()
  22. {
  23.   register int   loop1cnt, loop2cnt;
  24.   struct   tm    *sys_time;
  25.   long     start_time, end_time, l_time;
  26.   int      fhandle;
  27.   double   t_diff;
  28.  
  29.   /* ------------------------------------------------------------- */
  30.   /* display program logo                                          */
  31.   /* ------------------------------------------------------------- */
  32.   printf("FSPERF - file system performance test program\n");
  33.   printf("Version 1.00 Level 00\n\n");
  34.            
  35.   /* ------------------------------------------------------------- */
  36.   /* create file, write 256 records and close it                   */
  37.   /* ------------------------------------------------------------- */
  38.   printf("preparing test...\r");
  39.   fhandle = open(filename, O_BINARY | O_CREAT | O_RDWR, S_IREAD | S_IWRITE);
  40.   if (fhandle == 0) {
  41.      perror("\nerror creating/opening file\n\n");
  42.      exit(1);
  43.   }
  44.  
  45.   lseek(fhandle, 0L, SEEK_SET);
  46.  
  47.   for (loop1cnt =0; loop1cnt < TESTCOUNT2; loop1cnt++)
  48.      write(fhandle, fbuffer, 2048);
  49.  
  50.   close(fhandle);
  51.  
  52.   /* ------------------------------------------------------------- */
  53.   /* write out date and time                                       */
  54.   /* ------------------------------------------------------------- */
  55.   start_time = time(&l_time);
  56.   printf("%s", ctime(&l_time));
  57.                
  58.   /* ------------------------------------------------------------- */
  59.   /* generate random positions for 512 bytes record length         */
  60.   /* ------------------------------------------------------------- */
  61.   printf("\n");
  62.   for (loop1cnt = 0; loop1cnt < TESTCOUNT1; loop1cnt++) {
  63.      fpos[loop1cnt] = (unsigned long) rand() * TESTCOUNT1 * 512L / RAND_MAX;
  64.   }
  65.  
  66.   /* ------------------------------------------------------------- */
  67.   /* test open                                                     */
  68.   /* ------------------------------------------------------------- */
  69.   start_time = time(&l_time);
  70.   fhandle = open(filename, O_RDWR | O_BINARY);
  71.   if (fhandle == 0) {
  72.      perror("error opening file\n\n");
  73.      exit(1);
  74.   }
  75.   end_time = time(&l_time);
  76.   t_diff = difftime(start_time, end_time);
  77.   printf("open : %1.0lf sec\n", difftime(end_time, start_time));
  78.  
  79.   /* ------------------------------------------------------------- */
  80.   /* test read sequential 512 bytes 8192 times forward             */
  81.   /* ------------------------------------------------------------- */
  82.   lseek(fhandle, 0L, SEEK_SET);
  83.   start_time = time(&l_time);
  84.   for (loop1cnt = 0; loop1cnt < TESTCOUNT1; loop1cnt++)
  85.      read(fhandle, fbuffer, 512);
  86.   end_time = time(&l_time);
  87.   printf("read 512 bytes %u times forward : %1.0lf sec\n", TESTCOUNT1, difftime(end_time, start_time));
  88.  
  89.   /* ------------------------------------------------------------- */
  90.   /* test read sequential 512 bytes 8192 times backward            */
  91.   /* ------------------------------------------------------------- */
  92.   lseek(fhandle, -512L, SEEK_END);
  93.   start_time = time(&l_time);
  94.   for (loop1cnt =0; loop1cnt < TESTCOUNT1; loop1cnt++) {
  95.      read(fhandle, fbuffer, 512);
  96.      lseek(fhandle, -1024L, SEEK_CUR);
  97.   }
  98.   end_time = time(&l_time);
  99.   printf("read 512 bytes %u times backward : %1.0lf sec\n", TESTCOUNT1, difftime(end_time, start_time));
  100.  
  101.   /* ------------------------------------------------------------- */
  102.   /* test read random 512 bytes 8192 times                         */
  103.   /* ------------------------------------------------------------- */
  104.   lseek(fhandle, 0L, SEEK_SET);
  105.   start_time = time(&l_time);
  106.   for (loop1cnt =0; loop1cnt < TESTCOUNT1; loop1cnt++) {
  107.      lseek(fhandle, fpos[loop1cnt], SEEK_SET);
  108.      read(fhandle, fbuffer, 512);
  109.   }
  110.   end_time = time(&l_time);
  111.   printf("read 512 bytes %u times random : %1.0lf sec\n", TESTCOUNT1, difftime(end_time, start_time));
  112.  
  113.   /* ------------------------------------------------------------- */
  114.   /* test write sequential 512 bytes 8192 times forward            */
  115.   /* ------------------------------------------------------------- */
  116.   lseek(fhandle, 0L, SEEK_SET);
  117.   start_time = time(&l_time);
  118.   for (loop1cnt = 0; loop1cnt < TESTCOUNT1; loop1cnt++)
  119.      write(fhandle, fbuffer, 512);
  120.   end_time = time(&l_time);
  121.   printf("write 512 bytes %u times forward : %1.0lf sec\n", TESTCOUNT1, difftime(end_time, start_time));
  122.  
  123.   /* ------------------------------------------------------------- */
  124.   /* test write sequential 512 bytes 8192 times backward           */
  125.   /* ------------------------------------------------------------- */
  126.   lseek(fhandle, -512L, SEEK_END);
  127.   start_time = time(&l_time);
  128.   for (loop1cnt =0; loop1cnt < TESTCOUNT1; loop1cnt++) {
  129.      write(fhandle, fbuffer, 512);
  130.      lseek(fhandle, -1024L, SEEK_CUR);
  131.   }
  132.   end_time = time(&l_time);
  133.   printf("write 512 bytes %u times backward : %1.0lf sec\n", TESTCOUNT1, difftime(end_time, start_time));
  134.  
  135.   /* ------------------------------------------------------------- */
  136.   /* test write random 512 bytes 8192 times                        */
  137.   /* ------------------------------------------------------------- */
  138.   lseek(fhandle, 0L, SEEK_SET);
  139.   start_time = time(&l_time);
  140.   for (loop1cnt =0; loop1cnt < TESTCOUNT1; loop1cnt++) {
  141.      lseek(fhandle, fpos[loop1cnt], SEEK_SET);
  142.      write(fhandle, fbuffer, 512);
  143.   }
  144.   end_time = time(&l_time);
  145.   printf("write 512 bytes %u times random : %1.0lf sec\n", TESTCOUNT1, difftime(end_time, start_time));
  146.  
  147.   /* ------------------------------------------------------------- */
  148.   /* test read-rewrite random 512 bytes 8192 times                 */
  149.   /* ------------------------------------------------------------- */
  150.   lseek(fhandle, 0L, SEEK_SET);
  151.   start_time = time(&l_time);
  152.   for (loop1cnt =0; loop1cnt < TESTCOUNT1; loop1cnt++) {
  153.      lseek(fhandle, fpos[loop1cnt], SEEK_SET);
  154.      read(fhandle, fbuffer, 512);
  155.      write(fhandle, fbuffer, 512);
  156.   }
  157.   end_time = time(&l_time);
  158.   printf("read-rewrite 512 bytes %u times random : %1.0lf sec\n", TESTCOUNT1, difftime(end_time, start_time));
  159.  
  160.  
  161.   /* ------------------------------------------------------------- */
  162.   /* generate random positions for 2048 bytes record length        */
  163.   /* ------------------------------------------------------------- */
  164.   printf("\n");
  165.   for (loop1cnt = 0; loop1cnt < TESTCOUNT2; loop1cnt++) {
  166.      fpos[loop1cnt] = (unsigned long) rand() * TESTCOUNT2 * 2048L / RAND_MAX;
  167.   }
  168.  
  169.   /* ------------------------------------------------------------- */
  170.   /* test read sequential 2048 bytes 2048 times forward            */
  171.   /* ------------------------------------------------------------- */
  172.   lseek(fhandle, 0L, SEEK_SET);
  173.   start_time = time(&l_time);
  174.   for (loop1cnt = 0; loop1cnt < TESTCOUNT2; loop1cnt++)
  175.      read(fhandle, fbuffer, 2048);
  176.   end_time = time(&l_time);
  177.   printf("read 2048 bytes %u times forward : %1.0lf sec\n", TESTCOUNT2, difftime(end_time, start_time));
  178.  
  179.   /* ------------------------------------------------------------- */
  180.   /* test read sequential 2048 bytes 2048 times backward           */
  181.   /* ------------------------------------------------------------- */
  182.   lseek(fhandle, -2048L, SEEK_END);
  183.   start_time = time(&l_time);
  184.   for (loop1cnt =0; loop1cnt < TESTCOUNT2; loop1cnt++) {
  185.      read(fhandle, fbuffer, 2048);
  186.      lseek(fhandle, -4096L, SEEK_CUR);
  187.   }
  188.   end_time = time(&l_time);
  189.   printf("read 2048 bytes %u times backward : %1.0lf sec\n", TESTCOUNT2, difftime(end_time, start_time));
  190.  
  191.   /* ------------------------------------------------------------- */
  192.   /* test read random 2048 bytes 2048 times                        */
  193.   /* ------------------------------------------------------------- */
  194.   lseek(fhandle, 0L, SEEK_SET);
  195.   start_time = time(&l_time);
  196.   for (loop1cnt =0; loop1cnt < TESTCOUNT2; loop1cnt++) {
  197.      lseek(fhandle, fpos[loop1cnt], SEEK_SET);
  198.      read(fhandle, fbuffer, 2048);
  199.   }
  200.   end_time = time(&l_time);
  201.   printf("read 2048 bytes %u times random : %1.0lf sec\n", TESTCOUNT2, difftime(end_time, start_time));
  202.  
  203.   /* ------------------------------------------------------------- */
  204.   /* test write sequential 2048 bytes 2048 times forward           */
  205.   /* ------------------------------------------------------------- */
  206.   lseek(fhandle, 0L, SEEK_SET);
  207.   start_time = time(&l_time);
  208.   for (loop1cnt = 0; loop1cnt < TESTCOUNT2; loop1cnt++)
  209.      write(fhandle, fbuffer, 2048);
  210.   end_time = time(&l_time);
  211.   printf("write 2048 bytes %u times forward : %1.0lf sec\n", TESTCOUNT2, difftime(end_time, start_time));
  212.  
  213.   /* ------------------------------------------------------------- */
  214.   /* test write sequential 2048 bytes 2048 times backward          */
  215.   /* ------------------------------------------------------------- */
  216.   lseek(fhandle, -2048L, SEEK_END);
  217.   start_time = time(&l_time);
  218.   for (loop1cnt =0; loop1cnt < TESTCOUNT2; loop1cnt++) {
  219.      write(fhandle, fbuffer, 2048);
  220.      lseek(fhandle, -4096L, SEEK_CUR);
  221.   }
  222.   end_time = time(&l_time);
  223.   printf("write 2048 bytes %u times backward : %1.0lf sec\n", TESTCOUNT2, difftime(end_time, start_time));
  224.  
  225.   /* ------------------------------------------------------------- */
  226.   /* test write random 2048 bytes 2048 times                       */
  227.   /* ------------------------------------------------------------- */
  228.   lseek(fhandle, 0L, SEEK_SET);
  229.   start_time = time(&l_time);
  230.   for (loop1cnt =0; loop1cnt < TESTCOUNT2; loop1cnt++) {
  231.      lseek(fhandle, fpos[loop1cnt], SEEK_SET);
  232.      write(fhandle, fbuffer, 2048);
  233.   }
  234.   end_time = time(&l_time);
  235.   printf("write 2048 bytes %u times random : %1.0lf sec\n", TESTCOUNT2, difftime(end_time, start_time));
  236.  
  237.   /* ------------------------------------------------------------- */
  238.   /* test read-rewrite random 2048 bytes 2048 times                */
  239.   /* ------------------------------------------------------------- */
  240.   lseek(fhandle, 0L, SEEK_SET);
  241.   start_time = time(&l_time);
  242.   for (loop1cnt =0; loop1cnt < TESTCOUNT2; loop1cnt++) {
  243.      lseek(fhandle, fpos[loop1cnt], SEEK_SET);
  244.      read(fhandle, fbuffer, 2048);
  245.      write(fhandle, fbuffer, 2048);
  246.   }
  247.   end_time = time(&l_time);
  248.   printf("read-rewrite 2048 bytes %u times random : %1.0lf sec\n", TESTCOUNT2, difftime(end_time, start_time));
  249.                
  250.   /* ------------------------------------------------------------- */
  251.   /* test close                                                    */
  252.   /* ------------------------------------------------------------- */
  253.   start_time = time(&l_time);
  254.   close(fhandle);                                        
  255.   end_time = time(&l_time);
  256.   printf("close : %1.0lf sec\n", difftime(end_time, start_time));
  257.                
  258.   /* ------------------------------------------------------------- */
  259.   /* write out date and time                                       */
  260.   /* ------------------------------------------------------------- */
  261.   start_time = time(&l_time);
  262.   printf("%s", ctime(&l_time));
  263. }
  264.