home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / ae / test-file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  2.6 KB  |  100 lines

  1. /* test-file.c
  2.  James Larus, Jan. 1990
  3.  
  4.  Write a large file in various way to find the most efficient buffer size for
  5.  AE.
  6.  
  7.  Basically, this program writes out a 1MB buffer (but also try it with
  8.  8MBs if you have the disk space) in 4 ways:
  9.  
  10.  1. In a 1 MB chunk aligned on a pagesize boundary.
  11.  
  12.  2. In 32K chunks aligned on pagesize boundaries.
  13.  
  14.  3. In a 1 MB chunk not aligned on a boundary.
  15.  
  16.  4. In 32K chunks not aligned on boundaries.
  17.  
  18.  */
  19.  
  20.  
  21. #include <sys/file.h>
  22. #include <sys/time.h>
  23. #include <sys/resource.h>
  24.  
  25. #define SIZE 1048576        /* 2 ^ 20 */
  26. #define CHUNK 32768        /* 2 ^ 15 */
  27. #define JITTER 3
  28.  
  29. #define TD(te,ts) (float) (((te).tv_sec - (ts).tv_sec) * 1.0 \
  30.                + (((te).tv_usec - (ts).tv_usec) / 1000000.0))
  31.  
  32. char *malloc ();
  33.  
  34.  
  35. main (argc, argv)
  36.      int argc;
  37.      char *argv[];
  38. {
  39.  
  40.   register char *buf1, *buf2, *buf3, *buf4;
  41.   register int i;
  42.   register int f1, f2, f3, f4;
  43.   struct rusage start, end;
  44.   register int pagesize = getpagesize ();
  45.  
  46.   buf1 = malloc (SIZE + pagesize);
  47.   buf1 = (char *) ((int) (buf1 + pagesize - 1) & (~pagesize + 1));
  48.   buf2 = malloc (SIZE + pagesize);
  49.   buf2 = (char *) ((int) (buf2 + pagesize - 1) & (~pagesize + 1));
  50.   buf3 = malloc (SIZE + JITTER);
  51.   buf4 = malloc (SIZE + JITTER);
  52.  
  53.   for (i = 0; i < SIZE; i ++) buf1[i] = buf2[i] = buf3[i] = buf4[i] = i;
  54.   for (i = SIZE; i < SIZE + JITTER; i++) buf3[i] = buf4[i] = i;
  55.  
  56.   f1 = open ("file1", O_WRONLY | O_CREAT, 0644);
  57.   f2 = open ("file2", O_WRONLY | O_CREAT, 0644);
  58.   f3 = open ("file3", O_WRONLY | O_CREAT, 0644);
  59.   f4 = open ("file4", O_WRONLY | O_CREAT, 0644);
  60.  
  61.   getrusage(RUSAGE_SELF, &start);
  62.   write (f1, buf1, SIZE);
  63.   getrusage(RUSAGE_SELF, &end);
  64.   printf ("Write (%d): %.2fu + %.2fs\n", SIZE,
  65.       TD(end.ru_utime, start.ru_utime),
  66.       TD(end.ru_stime, start.ru_stime));
  67.   close (f1);
  68.   unlink("file1");
  69.  
  70.   getrusage(RUSAGE_SELF, &start);
  71.   for (i = 0; i < SIZE; i += CHUNK)
  72.     write (f2, buf2 + i, CHUNK);
  73.   getrusage(RUSAGE_SELF, &end);
  74.   printf ("Write (%d/%d): %.2fu + %.2fs\n", SIZE, CHUNK,
  75.       TD(end.ru_utime, start.ru_utime),
  76.       TD(end.ru_stime, start.ru_stime));
  77.   close (f2);
  78.   unlink("file2");
  79.  
  80.   getrusage(RUSAGE_SELF, &start);
  81.   write (f3, buf3 + JITTER, SIZE);
  82.   getrusage(RUSAGE_SELF, &end);
  83.   printf ("Write (%d + %d): %.2fu + %.2fs\n", SIZE, JITTER,
  84.       TD(end.ru_utime, start.ru_utime),
  85.       TD(end.ru_stime, start.ru_stime));
  86.   close (f3);
  87.   unlink("file3");
  88.  
  89.   getrusage(RUSAGE_SELF, &start);
  90.   for (i = 0; i < SIZE; i += CHUNK)
  91.     write (f4, buf4 + JITTER + i, CHUNK);
  92.   getrusage(RUSAGE_SELF, &end);
  93.   printf ("Write ((%d + %d)/%d): %.2fu + %.2fs\n", SIZE, JITTER, CHUNK,
  94.       TD(end.ru_utime, start.ru_utime),
  95.       TD(end.ru_stime, start.ru_stime));
  96.  
  97.   close (f4);
  98.   unlink("file4");
  99. }
  100.