1 /* This file is part of the Zebra server.
2 Copyright (C) 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
23 #include <yaz/options.h>
25 #include <sys/times.h>
34 #include <yaz/xmalloc.h>
35 #include <yaz/timing.h>
36 #include <idzebra/isamb.h>
39 static void log_item(int level, const void *b, const char *txt)
42 memcpy(&x, b, sizeof(int));
43 yaz_log(YLOG_LOG, "%s %d", txt, x);
46 static void log_pr(const char *txt)
48 yaz_log(YLOG_LOG, "%s", txt);
51 int compare_item(const void *a, const void *b)
55 memcpy(&ia, (const char *) a + 1, sizeof(int));
56 memcpy(&ib, (const char *) b + 1, sizeof(int));
64 void *code_start(void)
69 void code_item(void *p, char **dst, const char **src)
72 memcpy (*dst, *src, sz);
77 void code_reset(void *p)
80 void code_stop(void *p)
94 int code_read(void *vp, char **dst, int *insertMode)
96 struct read_info *ri = (struct read_info *)vp;
99 if (ri->no >= ri->max)
104 memset(*dst, 0, ri->sz);
106 memcpy(*dst + 1, &x, sizeof(int));
110 ri->val = ri->val + ri->step;
111 *insertMode = ri->insertMode;
114 yaz_log(YLOG_LOG, "%d %5d", ri->insertMode, x);
119 void bench_insert(ISAMB isb, int number_of_trees,
120 int number_of_rounds, int number_of_elements,
124 ISAM_P *isamc_p = xmalloc(sizeof(ISAM_P) * number_of_trees);
128 for (i = 0; i<number_of_trees; i++)
129 isamc_p[i] = 0; /* initially, is empty */
134 ri.sz = sizeof(int) + 1 + extra_size;
136 for (round = 0; round < number_of_rounds; round++)
138 yaz_timing_t t = yaz_timing_create();
141 for (i = 0; i<number_of_trees; i++)
144 /* insert a number of entries */
148 if (RAND_MAX < 65536)
149 ri.val = ri.val + 65536*rand();
151 // ri.val = number_of_elements * round;
152 ri.max = number_of_elements;
154 isamc_i.clientData = &ri;
155 isamc_i.read_item = code_read;
157 isamb_merge (isb, &isamc_p[i] , &isamc_i);
160 isamb_dump(isb, isamc_p[i], log_pr);
163 printf("%3d %8.6f %5.2f %5.2f\n",
165 yaz_timing_get_real(t),
166 yaz_timing_get_user(t),
167 yaz_timing_get_sys(t));
168 yaz_timing_destroy(&t);
173 void exit_usage(void)
175 fprintf(stderr, "benchisamb [-r rounds] [-n items] [-i isams]\n");
179 int main(int argc, char **argv)
186 int number_of_rounds = 10;
187 int number_of_items = 1000;
188 int number_of_isams = 1000;
192 while ((ret = options("z:r:n:i:", argv, argc, &arg)) != -2)
197 number_of_rounds = atoi(arg);
200 number_of_items = atoi(arg);
203 number_of_isams = atoi(arg);
206 extra_size = atoi(arg);
209 fprintf(stderr, "bad arg: %s\n", arg);
212 fprintf(stderr, "bad option.\n");
217 /* setup method (attributes) */
218 method.compare_item = compare_item;
219 method.log_item = log_item;
220 method.codec.start = code_start;
221 method.codec.encode = code_item;
222 method.codec.decode = code_item;
223 method.codec.reset = code_reset;
224 method.codec.stop = code_stop;
226 t = yaz_timing_create();
230 /* create block system */
231 bfs = bfs_create(0, 0);
234 yaz_log(YLOG_WARN, "bfs_create failed");
240 /* create isam handle */
241 isb = isamb_open (bfs, "isamb", 1, &method, 0);
244 yaz_log(YLOG_WARN, "isamb_open failed");
247 bench_insert(isb, number_of_isams, number_of_rounds, number_of_items,
252 /* exit block system */
256 printf("Total %8.6f %5.2f %5.2f\n",
257 yaz_timing_get_real(t),
258 yaz_timing_get_user(t),
259 yaz_timing_get_sys(t));
260 yaz_timing_destroy(&t);
267 * c-file-style: "Stroustrup"
268 * indent-tabs-mode: nil
270 * vim: shiftwidth=4 tabstop=8 expandtab