]> mj.ucw.cz Git - libucw.git/blobdiff - lib/db-test.c
Merge with git+ssh://git.ucw.cz/projects/sherlock/GIT/sherlock.git
[libucw.git] / lib / db-test.c
index d4dc4a2f512122c4ef83a5634913a1e89680680b..9a6f3bb6264e19620970226474d15ab85d7bb083 100644 (file)
@@ -1,18 +1,21 @@
 /*
- *     Sherlock Library -- Database Manager -- Tests and Benchmarks
+ *     UCW Library -- Database Manager -- Tests and Benchmarks
  *
- *     (c) 1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
+ *     (c) 1999 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
  */
 
 #if 1
-#include "db.c"
+#include "lib/db.c"
 #define NAME "SDBM"
 #else
-#include "db-emul.c"
+#include "lib/db-emul.c"
 #define NAME "GDBM"
 #endif
 
-#include <getopt.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <stdarg.h>
 #include <sys/stat.h>
@@ -45,6 +48,7 @@ Options:\n\
 -kU            Use keys with URL distribution\n\
 -n<n>          Number of distinct keys\n\
 -d<m>[-<n>]    Use specified value size (see -k<m>-<n>)\n\
+-t             Perform the tests on an existing database file\n\
 -v             Be verbose\n\
 -s             Turn on synchronous mode\n\
 -S             Turn on supersynchronous mode\n\
@@ -257,11 +261,13 @@ int main(int argc, char **argv)
   byte kb[2048], vb[2048], vb2[2048];
   uns ks, vs, vs2, perc, cnt;
   char *ch;
+  int dont_delete = 0;
+  timestamp_t timer;
 
-  initlog("dbtest");
+  log_init("dbtest");
   setvbuf(stdout, NULL, _IONBF, 0);
   setvbuf(stderr, NULL, _IONBF, 0);
-  while ((c = getopt(argc, argv, "c:p:k:n:d:vsSF")) >= 0)
+  while ((c = getopt(argc, argv, "c:p:k:n:d:vsStF")) >= 0)
     switch (c)
       {
       case 'c':
@@ -294,6 +300,9 @@ int main(int argc, char **argv)
       case 'F':
        opts.flags |= SDBM_FAST;
        break;
+      case 't':
+       dont_delete = 1;
+       break;
       default:
        help();
       }
@@ -316,7 +325,8 @@ int main(int argc, char **argv)
 
   verb("OPEN(%s, key=%d, val=%d, cache=%d, pgorder=%d)\n", opts.name, opts.key_size, opts.val_size,
        opts.cache_size, opts.page_order);
-  unlink(opts.name);
+  if (!dont_delete)
+    unlink(opts.name);
   d = sdbm_open(&opts);
   if (!d)
     die("open failed: %m");
@@ -324,7 +334,7 @@ int main(int argc, char **argv)
   while (optind < argc)
     {
       char *o = argv[optind++];
-      init_timer();
+      init_timer(&timer);
       switch (*o)
        {
        case 'c':
@@ -450,7 +460,7 @@ int main(int argc, char **argv)
          help();
        }
       sdbm_sync(d);
-      printf("%d ms\n", get_timer());
+      printf("%d ms\n", get_timer(&timer));
     }
 
   verb("CLOSE\n");