1 /* $Id: benchisamb.c,v 1.1 2006-12-09 08:03:57 adam Exp $
2 Copyright (C) 1995-2006
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <yaz/options.h>
25 #include <sys/times.h>
34 #include <yaz/xmalloc.h>
35 #include <idzebra/isamb.h>
38 static void log_item(int level, const void *b, const char *txt)
41 memcpy(&x, b, sizeof(int));
42 yaz_log(YLOG_LOG, "%s %d", txt, x);
45 static void log_pr(const char *txt)
47 yaz_log(YLOG_LOG, "%s", txt);
50 int compare_item(const void *a, const void *b)
54 memcpy(&ia, a, sizeof(int));
55 memcpy(&ib, b, sizeof(int));
63 void *code_start(void)
68 void code_item(void *p, char **dst, const char **src)
70 memcpy (*dst, *src, sizeof(int));
71 (*dst) += sizeof(int);
72 (*src) += sizeof(int);
75 void code_reset(void *p)
78 void code_stop(void *p)
91 int code_read(void *vp, char **dst, int *insertMode)
93 struct read_info *ri = (struct read_info *)vp;
96 if (ri->no >= ri->max)
101 memcpy (*dst, &x, sizeof(int));
104 ri->val = ri->val + ri->step;
105 *insertMode = ri->insertMode;
108 yaz_log(YLOG_LOG, "%d %5d", ri->insertMode, x);
113 void bench_insert(ISAMB isb, int number_of_trees,
114 int number_of_rounds, int number_of_elements)
117 ISAM_P *isamc_p = xmalloc(sizeof(ISAM_P) * number_of_trees);
121 for (i = 0; i<number_of_trees; i++)
122 isamc_p[i] = 0; /* initially, is empty */
128 for (round = 0; round < number_of_rounds; round++)
132 struct tms tms1, tms2;
133 struct timeval start_time, end_time;
136 gettimeofday(&start_time, 0);
139 for (i = 0; i<number_of_trees; i++)
142 /* insert a number of entries */
146 // ri.val = number_of_elements * round;
147 ri.max = number_of_elements;
149 isamc_i.clientData = &ri;
150 isamc_i.read_item = code_read;
152 isamb_merge (isb, &isamc_p[i] , &isamc_i);
155 isamb_dump(isb, isamc_p[i], log_pr);
160 gettimeofday(&end_time, 0);
163 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000.0 +
164 end_time.tv_usec - start_time.tv_usec;
166 printf("%3d %8.6f %5.2f %5.2f\n",
169 (double) (tms2.tms_utime - tms1.tms_utime)/100,
170 (double) (tms2.tms_stime - tms1.tms_stime)/100);
178 int main(int argc, char **argv)
185 int number_of_rounds = 10;
186 int number_of_items = 1000;
187 int number_of_isams = 1000;
189 while ((ret = options("r:n:i:", argv, argc, &arg)) != -2)
194 number_of_rounds = atoi(arg);
197 number_of_items = atoi(arg);
200 number_of_isams = atoi(arg);
203 fprintf(stderr, "bad arg: %s\n", arg);
206 fprintf(stderr, "bad option. %s\n", ret);
211 /* setup method (attributes) */
212 method.compare_item = compare_item;
213 method.log_item = log_item;
214 method.codec.start = code_start;
215 method.codec.encode = code_item;
216 method.codec.decode = code_item;
217 method.codec.reset = code_reset;
218 method.codec.stop = code_stop;
220 /* create block system */
221 bfs = bfs_create(0, 0);
224 yaz_log(YLOG_WARN, "bfs_create failed");
230 /* create isam handle */
231 isb = isamb_open (bfs, "isamb", 1, &method, 0);
234 yaz_log(YLOG_WARN, "isamb_open failed");
237 bench_insert(isb, number_of_isams, number_of_rounds, number_of_items);
241 /* exit block system */
249 * indent-tabs-mode: nil
251 * vim: shiftwidth=4 tabstop=8 expandtab