Reformat: delete trailing whitespace
[idzebra-moved-to-github.git] / isamb / tstisamb.c
index 4103211..d48d837 100644 (file)
@@ -1,8 +1,5 @@
-/* $Id: tstisamb.c,v 1.26 2006-12-07 21:13:56 adam Exp $
-   Copyright (C) 1995-2006
-   Index Data ApS
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+   Copyright (C) 1994-2011 Index Data
 
 Zebra is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -20,6 +17,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 */
 
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 #if HAVE_SYS_TIMES_H
 #include <sys/times.h>
 #endif
@@ -34,16 +34,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <idzebra/isamb.h>
 #include <assert.h>
 
+static int log_level = 0;
+
 static void log_item(int level, const void *b, const char *txt)
 {
     int x;
     memcpy(&x, b, sizeof(int));
-    yaz_log(YLOG_DEBUG, "%s %d", txt, x);
+    yaz_log(log_level, "%s %d", txt, x);
 }
 
 static void log_pr(const char *txt)
 {
-    yaz_log(YLOG_DEBUG, "%s", txt);
+    yaz_log(log_level, "%s", txt);
 }
 
 int compare_item(const void *a, const void *b)
@@ -104,70 +106,11 @@ int code_read(void *vp, char **dst, int *insertMode)
     *insertMode = ri->insertMode;
 
 #if 0
-    yaz_log(YLOG_LOG, "%d %5d", ri->insertMode, x);
+    yaz_log(log_level, "%d %5d", ri->insertMode, x);
 #endif
     return 1;
 }
 
-void bench_insert(ISAMB isb, int number_of_trees,
-                int number_of_rounds, int number_of_elements)
-{
-    ISAMC_I isamc_i;
-    ISAM_P *isamc_p = xmalloc(sizeof(ISAM_P) * number_of_trees);
-    struct read_info ri;
-    int round, i;
-
-    for (i = 0; i<number_of_trees; i++)
-        isamc_p[i] = 0; /* initially, is empty */
-
-    ri.val = 0;
-    ri.step = 1;
-    ri.insertMode = 1;
-    
-    for (round = 0; round < number_of_rounds; round++)
-    {
-#if HAVE_SYS_TIMES_H
-#if HAVE_SYS_TIME_H
-        struct tms tms1, tms2;
-        struct timeval start_time, end_time;
-        double usec;
-        times(&tms1);
-        gettimeofday(&start_time, 0);
-#endif
-#endif
-        for (i = 0; i<number_of_trees; i++)
-        {
-
-            /* insert a number of entries */
-            ri.no = 0;
-            
-            ri.val = (rand());
-            ri.max = number_of_elements;
-            
-            isamc_i.clientData = &ri;
-            isamc_i.read_item = code_read;
-            
-            
-            isamb_merge (isb, &isamc_p[i] , &isamc_i);
-        }
-#if HAVE_SYS_TIMES_H
-#if HAVE_SYS_TIME_H      
-        gettimeofday(&end_time, 0);
-        times(&tms2);
-        
-        usec = (end_time.tv_sec - start_time.tv_sec) * 1000000.0 +
-            end_time.tv_usec - start_time.tv_usec;
-        
-        yaz_log (YLOG_LOG, "round=%d times: %5.4f %5.2f %5.2f",
-                 round,
-                 usec / 1000000,
-                 (double) (tms2.tms_utime - tms1.tms_utime)/100,
-                 (double) (tms2.tms_stime - tms1.tms_stime)/100);
-#endif
-#endif
-    }
-}
-
 void tst_insert(ISAMB isb, int n)
 {
     ISAMC_I isamc_i;
@@ -187,7 +130,7 @@ void tst_insert(ISAMB isb, int n)
 
     isamc_i.clientData = &ri;
     isamc_i.read_item = code_read;
-    
+
     isamc_p = 0; /* new list */
     isamb_merge (isb, &isamc_p , &isamc_i);
 
@@ -206,7 +149,7 @@ void tst_insert(ISAMB isb, int n)
            nerrs++;
        }
        else if (nerrs)
-           yaz_log(YLOG_LOG, "isamb_pp_read. n=%d Got %d",
+           yaz_log(log_level, "isamb_pp_read. n=%d Got %d",
                    n, x);
 
        ri.val++;
@@ -231,7 +174,7 @@ void tst_insert(ISAMB isb, int n)
 
     isamc_i.clientData = &ri;
     isamc_i.read_item = code_read;
-    
+
     isamb_merge (isb, &isamc_p , &isamc_i);
 
     /* delete a number of entries (odd ones) */
@@ -244,7 +187,7 @@ void tst_insert(ISAMB isb, int n)
 
     isamc_i.clientData = &ri;
     isamc_i.read_item = code_read;
-    
+
     isamb_merge (isb, &isamc_p, &isamc_i);
 
     if (isamc_p)
@@ -273,13 +216,13 @@ void tst_forward(ISAMB isb, int n)
 
     isamc_i.clientData = &ri;
     isamc_i.read_item = code_read;
-    
+
     isamc_p = 0;
     isamb_merge (isb, &isamc_p, &isamc_i);
 
     /* read the entries */
     pp = isamb_pp_open (isb, isamc_p, 1);
-    
+
     for (i = 0; i<ri.max; i +=2 )
     {
        int x = -1;
@@ -294,7 +237,7 @@ void tst_forward(ISAMB isb, int n)
        ri.no++;
     }
     isamb_pp_close(pp);
-    
+
     pp = isamb_pp_open (isb, isamc_p, 1);
     for (i = 0; i<ri.max; i += 100)
     {
@@ -358,10 +301,10 @@ void tst_append(ISAMB isb, int n)
        ri.val = 0;
        ri.step = 1;
        ri.insertMode = 1;
-       
+
        isamc_i.clientData = &ri;
        isamc_i.read_item = code_read;
-       
+
        isamb_merge (isb, &isamb_p , &isamc_i);
     }
 }
@@ -386,7 +329,7 @@ int tst_random_read(void *vp, char **dst, int *insertMode)
     }
     if (ri->idx >= ri->max)
        return 0;
-    
+
     if (ri->delta[ri->idx] > 0)
     {
        ri->level++;
@@ -414,7 +357,7 @@ void tst_random(ISAMB isb, int n, int rounds, int max_dups)
     int i, j;
     for (i = 0; i<n; i++)
        freq[i] = 0;
-    
+
     for (j = 0; j<rounds; j++)
     {
        yaz_log(YLOG_DEBUG, "round %d", j);
@@ -429,18 +372,18 @@ void tst_random(ISAMB isb, int n, int rounds, int max_dups)
        {
            ISAMC_I isamc_i;
            struct random_read_info ri;
-           
+
            ri.delta = delta;
            ri.idx = 0;
            ri.max = n;
            ri.level = 0;
-           
+
            isamc_i.clientData = &ri;
            isamc_i.read_item = tst_random_read;
 
            isamb_merge (isb, &isamb_p , &isamc_i);
        }
-       
+
        yaz_log(YLOG_DEBUG, "dump %d", j);
        isamb_dump(isb, isamb_p, log_pr);
 
@@ -521,7 +464,7 @@ void tst_minsert(ISAMB isb, int n)
     isamc_i.clientData = &ri;
 
     /* all have same value = 1 */
-    ri.val = 1;  
+    ri.val = 1;
     ri.step = 0;
 
     isamc_i.read_item = code_read;
@@ -534,7 +477,7 @@ void tst_minsert(ISAMB isb, int n)
     isamb_merge (isb, &isamb_p , &isamc_i);
 
     isamb_dump(isb, isamb_p, log_pr);
-    
+
     ri.no = 0;
     ri.max = n - n/2;
 
@@ -592,10 +535,10 @@ int main(int argc, char **argv)
     BFiles bfs;
     ISAMB isb;
     ISAMC_M method;
-    
+
     if (argc == 2)
        yaz_log_init_level(YLOG_ALL);
-       
+
     /* setup method (attributes) */
     method.compare_item = compare_item;
     method.log_item = log_item;
@@ -622,9 +565,6 @@ int main(int argc, char **argv)
        yaz_log(YLOG_WARN, "isamb_open failed");
        exit(2);
     }
-#if 0
-    bench_insert(isb, 1000, 100, 10000);
-#else
     tst_insert(isb, 1);
     tst_insert(isb, 2);
     tst_insert(isb, 20);
@@ -637,11 +577,10 @@ int main(int argc, char **argv)
     tst_x(isb);
 
     tst_append(isb, 1000);
-#endif
 
     if (0)
        identical_keys_tests(isb);
-    
+
     isamb_close(isb);
 
     /* exit block system */
@@ -652,6 +591,7 @@ int main(int argc, char **argv)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab