]> mj.ucw.cz Git - libucw.git/commitdiff
Improved the file benchmark slightly.
authorMartin Mares <mj@ucw.cz>
Fri, 24 Nov 2006 00:04:31 +0000 (01:04 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 24 Nov 2006 00:04:31 +0000 (01:04 +0100)
debug/sorter/file-test.c

index 9ea4084ca3ac061f6605bf11f7e47f9fb5911c54..c1672d298ea070d0212675b8d4c3d1f95f730db3 100644 (file)
@@ -3,6 +3,7 @@
  */
 
 #include "lib/lib.h"
+#include "lib/lfs.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -13,8 +14,8 @@ int main(int argc, char **argv)
 {
   ASSERT(argc == 4);
   uns files = atol(argv[1]);
-  uns bufsize = atol(argv[2]);
-  uns rounds = atol(argv[3]);
+  uns bufsize = atol(argv[2]) * 1024;                          // Kbytes
+  uns rounds = (u64)atol(argv[3]) * 1024*1024 / bufsize;       // Mbytes
   int fd[files];
   byte *buf[files];
 
@@ -23,7 +24,7 @@ int main(int argc, char **argv)
     {
       byte name[16];
       sprintf(name, "tmp/ft-%d", i);
-      fd[i] = open(name, O_RDWR | O_CREAT | O_TRUNC, 0666);
+      fd[i] = sh_open(name, O_RDWR | O_CREAT | O_TRUNC, 0666);
       if (fd[i] < 0)
        die("Cannot create %s: %m", name);
       buf[i] = big_alloc(bufsize);
@@ -31,21 +32,32 @@ int main(int argc, char **argv)
   sync();
 
   log(L_INFO, "Writing %d files in parallel with %d byte buffers", files, bufsize);
+  init_timer();
+  u64 total = 0, total_rep = 0;
   for (uns r=0; r<rounds; r++)
     {
-      log(L_INFO, "\tRound %d", r);
       for (uns i=0; i<files; i++)
        {
          for (uns j=0; j<bufsize; j++)
            buf[i][j] = r+i+j;
          uns c = write(fd[i], buf[i], bufsize);
          ASSERT(c == bufsize);
+         total += c;
+          if (total >= total_rep + 1024*1024*1024)
+           {
+             printf("Wrote %d MB (round %d of %d)\r", (int)(total >> 20), r, rounds);
+             fflush(stdout);
+             total_rep = total;
+           }
        }
     }
   log(L_INFO, "Syncing");
   sync();
+  uns ms = get_timer();
+  log(L_INFO, "Spent %dms (%d MB/sec)", ms, (uns)(total/ms*1000/1048576));
 
   log(L_INFO, "Reading the files sequentially");
+  total = total_rep = 0;
   for (uns i=0; i<files; i++)
     {
       lseek(fd[i], 0, SEEK_SET);
@@ -53,9 +65,18 @@ int main(int argc, char **argv)
        {
          uns c = read(fd[i], buf[i], bufsize);
          ASSERT(c == bufsize);
+         total += c;
+          if (total >= total_rep + 1024*1024*1024)
+           {
+             printf("Read %d MB (file %d)\r", (int)(total >> 20), i);
+             fflush(stdout);
+             total_rep = total;
+           }
        }
       close(fd[i]);
     }
+  ms = get_timer();
+  log(L_INFO, "Spent %dms (%d MB/sec)", ms, (uns)(total/ms*1000/1048576));
 
   log(L_INFO, "Done");
   return 0;