Added some performance test utilities.
authorAdam Dickmeiss <adam@indexdata.dk>
Sat, 9 Dec 2006 08:03:57 +0000 (08:03 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Sat, 9 Dec 2006 08:03:57 +0000 (08:03 +0000)
isamb/.cvsignore
isamb/Makefile.am
isamb/bench1.plt [new file with mode: 0644]
isamb/bench1.sh [new file with mode: 0755]
isamb/benchisamb.c [new file with mode: 0644]
isamb/tstisamb.c

index 1a309ec..2f5499e 100644 (file)
@@ -4,5 +4,8 @@ Makefile
 Makefile.in
 *.mf
 tstisamb
+benchisamb
 *.lo
 *.la
+*.dat
+*.eps
index eb89f4c..1624001 100644 (file)
@@ -1,9 +1,12 @@
-## $Id: Makefile.am,v 1.13 2006-07-05 15:03:48 adam Exp $
+## $Id: Makefile.am,v 1.14 2006-12-09 08:03:57 adam Exp $
 
 noinst_LTLIBRARIES = libidzebra-isamb.la
 
+noinst_PROGRAMS = benchisamb
 check_PROGRAMS = tstisamb
 
+EXTRA_DIST = bench1.sh bench1.plt
+
 TESTS = $(check_PROGRAMS)
 
 tstisamb_SOURCES = tstisamb.c
@@ -11,6 +14,11 @@ tstisamb_LDADD = libidzebra-isamb.la \
  ../bfile/libidzebra-bfile.la \
  ../util/libidzebra-util.la $(YAZLALIB)
 
+benchisamb_SOURCES = benchisamb.c
+benchisamb_LDADD = libidzebra-isamb.la \
+ ../bfile/libidzebra-bfile.la \
+ ../util/libidzebra-util.la $(YAZLALIB)
+
 libidzebra_isamb_la_SOURCES = isamb.c
 
 AM_CPPFLAGS=-I$(srcdir)/../include $(YAZINC)
diff --git a/isamb/bench1.plt b/isamb/bench1.plt
new file mode 100644 (file)
index 0000000..a6c3f35
--- /dev/null
@@ -0,0 +1,8 @@
+set terminal postscript eps
+set output "bench1.eps"
+set xlabel "R"
+set ylabel "time"
+plot "1000x1000.dat" title "isam 1000" with linespoints, \
+     "100x10000.dat" title "isam 100" with linespoints, \
+     "10x100000.dat" title "isam 10" with linespoints, \
+     "1x1000000.dat" title "isam 1" with linespoints
diff --git a/isamb/bench1.sh b/isamb/bench1.sh
new file mode 100755 (executable)
index 0000000..1a91cd3
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+# $Id: bench1.sh,v 1.1 2006-12-09 08:03:57 adam Exp $
+# Test for variations of number of trees.. Total number of entries is
+# Constant 1 mio
+CMD="./benchisamb -r 50"
+
+$CMD -i 1000 -n 1000 >1000x1000.dat
+sleep 2
+$CMD -i 100 -n 10000 >100x10000.dat
+sleep 2
+$CMD -i 10 -n 100000 >10x100000.dat
+sleep 2
+$CMD -i 1 -n 1000000 >1x1000000.dat
diff --git a/isamb/benchisamb.c b/isamb/benchisamb.c
new file mode 100644 (file)
index 0000000..f252a4f
--- /dev/null
@@ -0,0 +1,253 @@
+/* $Id: benchisamb.c,v 1.1 2006-12-09 08:03:57 adam Exp $
+   Copyright (C) 1995-2006
+   Index Data ApS
+
+This file is part of the Zebra server.
+
+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
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+*/
+
+#include <yaz/options.h>
+#if HAVE_SYS_TIMES_H
+#include <sys/times.h>
+#endif
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <yaz/log.h>
+#include <yaz/xmalloc.h>
+#include <idzebra/isamb.h>
+#include <assert.h>
+
+static void log_item(int level, const void *b, const char *txt)
+{
+    int x;
+    memcpy(&x, b, sizeof(int));
+    yaz_log(YLOG_LOG, "%s %d", txt, x);
+}
+
+static void log_pr(const char *txt)
+{
+    yaz_log(YLOG_LOG, "%s", txt);
+}
+
+int compare_item(const void *a, const void *b)
+{
+    int ia, ib;
+
+    memcpy(&ia, a, sizeof(int));
+    memcpy(&ib, b, sizeof(int));
+    if (ia > ib)
+       return 1;
+    if (ia < ib)
+       return -1;
+   return 0;
+}
+
+void *code_start(void)
+{
+    return 0;
+}
+
+void code_item(void *p, char **dst, const char **src)
+{
+    memcpy (*dst, *src, sizeof(int));
+    (*dst) += sizeof(int);
+    (*src) += sizeof(int);
+}
+
+void code_reset(void *p)
+{
+}
+void code_stop(void *p)
+{
+}
+
+struct read_info {
+    int val;
+    int step;
+
+    int no;
+    int max;
+    int insertMode;
+};
+
+int code_read(void *vp, char **dst, int *insertMode)
+{
+    struct read_info *ri = (struct read_info *)vp;
+    int x;
+
+    if (ri->no >= ri->max)
+       return 0;
+    ri->no++;
+
+    x = ri->val;
+    memcpy (*dst, &x, sizeof(int));
+    (*dst)+=sizeof(int);
+
+    ri->val = ri->val + ri->step;
+    *insertMode = ri->insertMode;
+
+#if 0
+    yaz_log(YLOG_LOG, "%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.val = number_of_elements * round;
+            ri.max = number_of_elements;
+            
+            isamc_i.clientData = &ri;
+            isamc_i.read_item = code_read;
+            
+            isamb_merge (isb, &isamc_p[i] , &isamc_i);
+
+#if 0
+            isamb_dump(isb, isamc_p[i], log_pr);
+#endif       
+        }
+#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;
+        
+        printf("%3d %8.6f %5.2f %5.2f\n",
+                 round+1,
+                 usec / 1000000,
+                 (double) (tms2.tms_utime - tms1.tms_utime)/100,
+                 (double) (tms2.tms_stime - tms1.tms_stime)/100);
+#endif
+#endif
+    }
+    xfree(isamc_p);
+}
+
+
+int main(int argc, char **argv)
+{
+    BFiles bfs;
+    ISAMB isb;
+    ISAMC_M method;
+    int ret;
+    char *arg;
+    int number_of_rounds = 10;
+    int number_of_items = 1000;
+    int number_of_isams = 1000;
+
+    while ((ret = options("r:n:i:", argv, argc, &arg)) != -2)
+    {
+        switch(ret)
+        {
+        case 'r':
+            number_of_rounds = atoi(arg);
+            break;
+        case 'n':
+            number_of_items = atoi(arg);
+            break;
+        case 'i':
+            number_of_isams = atoi(arg);
+            break;
+        case 0:
+            fprintf(stderr, "bad arg: %s\n", arg);
+            exit(1);
+        default:
+            fprintf(stderr, "bad option. %s\n", ret);
+            exit(1);
+        }
+    }
+       
+    /* setup method (attributes) */
+    method.compare_item = compare_item;
+    method.log_item = log_item;
+    method.codec.start = code_start;
+    method.codec.encode = code_item;
+    method.codec.decode = code_item;
+    method.codec.reset = code_reset;
+    method.codec.stop = code_stop;
+
+    /* create block system */
+    bfs = bfs_create(0, 0);
+    if (!bfs)
+    {
+       yaz_log(YLOG_WARN, "bfs_create failed");
+       exit(1);
+    }
+
+    bf_reset(bfs);
+
+    /* create isam handle */
+    isb = isamb_open (bfs, "isamb", 1, &method, 0);
+    if (!isb)
+    {
+       yaz_log(YLOG_WARN, "isamb_open failed");
+       exit(2);
+    }
+    bench_insert(isb, number_of_isams, number_of_rounds, number_of_items);
+    
+    isamb_close(isb);
+
+    /* exit block system */
+    bfs_destroy(bfs);
+    exit(0);
+    return 0;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
index 4103211..7fe7d59 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: tstisamb.c,v 1.26 2006-12-07 21:13:56 adam Exp $
+/* $Id: tstisamb.c,v 1.27 2006-12-09 08:03:57 adam Exp $
    Copyright (C) 1995-2006
    Index Data ApS
 
@@ -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;
@@ -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++;
@@ -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,7 +577,6 @@ int main(int argc, char **argv)
     tst_x(isb);
 
     tst_append(isb, 1000);
-#endif
 
     if (0)
        identical_keys_tests(isb);