1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2009 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <yaz/options.h>
22 #include <sys/times.h>
31 #include <yaz/xmalloc.h>
32 #include <yaz/timing.h>
33 #include <idzebra/isamb.h>
36 static void log_item(int level, const void *b, const char *txt)
39 memcpy(&x, b, sizeof(int));
40 yaz_log(YLOG_LOG, "%s %d", txt, x);
43 static void log_pr(const char *txt)
45 yaz_log(YLOG_LOG, "%s", txt);
48 int compare_item(const void *a, const void *b)
52 memcpy(&ia, (const char *) a + 1, sizeof(int));
53 memcpy(&ib, (const char *) b + 1, sizeof(int));
61 void *code_start(void)
66 void code_item(void *p, char **dst, const char **src)
69 memcpy (*dst, *src, sz);
74 void code_reset(void *p)
77 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 memset(*dst, 0, ri->sz);
103 memcpy(*dst + 1, &x, sizeof(int));
107 ri->val = ri->val + ri->step;
108 *insertMode = ri->insertMode;
111 yaz_log(YLOG_LOG, "%d %5d", ri->insertMode, x);
116 void bench_insert(ISAMB isb, int number_of_trees,
117 int number_of_rounds, int number_of_elements,
121 ISAM_P *isamc_p = xmalloc(sizeof(ISAM_P) * number_of_trees);
125 for (i = 0; i<number_of_trees; i++)
126 isamc_p[i] = 0; /* initially, is empty */
131 ri.sz = sizeof(int) + 1 + extra_size;
133 for (round = 0; round < number_of_rounds; round++)
135 yaz_timing_t t = yaz_timing_create();
138 for (i = 0; i<number_of_trees; i++)
141 /* insert a number of entries */
145 if (RAND_MAX < 65536)
146 ri.val = ri.val + 65536*rand();
148 // ri.val = number_of_elements * round;
149 ri.max = number_of_elements;
151 isamc_i.clientData = &ri;
152 isamc_i.read_item = code_read;
154 isamb_merge (isb, &isamc_p[i] , &isamc_i);
157 isamb_dump(isb, isamc_p[i], log_pr);
160 printf("%3d %8.6f %5.2f %5.2f\n",
162 yaz_timing_get_real(t),
163 yaz_timing_get_user(t),
164 yaz_timing_get_sys(t));
165 yaz_timing_destroy(&t);
170 void exit_usage(void)
172 fprintf(stderr, "benchisamb [-r rounds] [-n items] [-i isams]\n");
176 int main(int argc, char **argv)
183 int number_of_rounds = 10;
184 int number_of_items = 1000;
185 int number_of_isams = 1000;
189 while ((ret = options("z: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 extra_size = atoi(arg);
206 fprintf(stderr, "bad arg: %s\n", arg);
209 fprintf(stderr, "bad option.\n");
214 /* setup method (attributes) */
215 method.compare_item = compare_item;
216 method.log_item = log_item;
217 method.codec.start = code_start;
218 method.codec.encode = code_item;
219 method.codec.decode = code_item;
220 method.codec.reset = code_reset;
221 method.codec.stop = code_stop;
223 t = yaz_timing_create();
227 /* create block system */
228 bfs = bfs_create(0, 0);
231 yaz_log(YLOG_WARN, "bfs_create failed");
237 /* create isam handle */
238 isb = isamb_open (bfs, "isamb", 1, &method, 0);
241 yaz_log(YLOG_WARN, "isamb_open failed");
244 bench_insert(isb, number_of_isams, number_of_rounds, number_of_items,
249 /* exit block system */
253 printf("Total %8.6f %5.2f %5.2f\n",
254 yaz_timing_get_real(t),
255 yaz_timing_get_user(t),
256 yaz_timing_get_sys(t));
257 yaz_timing_destroy(&t);
264 * c-file-style: "Stroustrup"
265 * indent-tabs-mode: nil
267 * vim: shiftwidth=4 tabstop=8 expandtab