1 /* $Id: benchisamb.c,v 1.3 2006-12-10 20:59:52 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, (const char *) a + 1, sizeof(int));
55 memcpy(&ib, (const char *) b + 1, sizeof(int));
63 void *code_start(void)
68 void code_item(void *p, char **dst, const char **src)
71 memcpy (*dst, *src, sz);
76 void code_reset(void *p)
79 void code_stop(void *p)
93 int code_read(void *vp, char **dst, int *insertMode)
95 struct read_info *ri = (struct read_info *)vp;
98 if (ri->no >= ri->max)
103 memset(*dst, 0, ri->sz);
105 memcpy(*dst + 1, &x, sizeof(int));
109 ri->val = ri->val + ri->step;
110 *insertMode = ri->insertMode;
113 yaz_log(YLOG_LOG, "%d %5d", ri->insertMode, x);
118 void bench_insert(ISAMB isb, int number_of_trees,
119 int number_of_rounds, int number_of_elements,
123 ISAM_P *isamc_p = xmalloc(sizeof(ISAM_P) * number_of_trees);
127 for (i = 0; i<number_of_trees; i++)
128 isamc_p[i] = 0; /* initially, is empty */
133 ri.sz = sizeof(int) + 1 + extra_size;
135 for (round = 0; round < number_of_rounds; round++)
139 struct tms tms1, tms2;
140 struct timeval start_time, end_time;
143 gettimeofday(&start_time, 0);
146 for (i = 0; i<number_of_trees; i++)
149 /* insert a number of entries */
153 if (RAND_MAX < 65536)
154 ri.val = ri.val + 65536*rand();
156 // ri.val = number_of_elements * round;
157 ri.max = number_of_elements;
159 isamc_i.clientData = &ri;
160 isamc_i.read_item = code_read;
162 isamb_merge (isb, &isamc_p[i] , &isamc_i);
165 isamb_dump(isb, isamc_p[i], log_pr);
169 gettimeofday(&end_time, 0);
172 usec = (end_time.tv_sec - start_time.tv_sec) * 1000000.0 +
173 end_time.tv_usec - start_time.tv_usec;
175 printf("%3d %8.6f %5.2f %5.2f\n",
178 (double) (tms2.tms_utime - tms1.tms_utime)/100,
179 (double) (tms2.tms_stime - tms1.tms_stime)/100);
186 void exit_usage(void)
188 fprintf(stderr, "benchisamb [-r rounds] [-n items] [-i isams]\n");
192 int main(int argc, char **argv)
199 int number_of_rounds = 10;
200 int number_of_items = 1000;
201 int number_of_isams = 1000;
204 while ((ret = options("z:r:n:i:", argv, argc, &arg)) != -2)
209 number_of_rounds = atoi(arg);
212 number_of_items = atoi(arg);
215 number_of_isams = atoi(arg);
218 extra_size = atoi(arg);
221 fprintf(stderr, "bad arg: %s\n", arg);
224 fprintf(stderr, "bad option.\n");
229 /* setup method (attributes) */
230 method.compare_item = compare_item;
231 method.log_item = log_item;
232 method.codec.start = code_start;
233 method.codec.encode = code_item;
234 method.codec.decode = code_item;
235 method.codec.reset = code_reset;
236 method.codec.stop = code_stop;
238 /* create block system */
239 bfs = bfs_create(0, 0);
242 yaz_log(YLOG_WARN, "bfs_create failed");
248 /* create isam handle */
249 isb = isamb_open (bfs, "isamb", 1, &method, 0);
252 yaz_log(YLOG_WARN, "isamb_open failed");
255 bench_insert(isb, number_of_isams, number_of_rounds, number_of_items,
260 /* exit block system */
268 * indent-tabs-mode: nil
270 * vim: shiftwidth=4 tabstop=8 expandtab