Fix warning
[yaz-moved-to-github.git] / util / benchmark.c
1 /* $Id: benchmark.c,v 1.3 2004-01-07 20:33:57 adam Exp $
2  * Copyright (C) 2003-2004 Index Data Aps
3  *
4  * This file is part of the YAZ toolkit.
5  *
6  * See the file LICENSE.
7  *
8  * This is an elementary benchmarker for server performance.  It works
9  * by repeatedly connecting to, seaching in and retrieving from the
10  * specified server, and keeps statistics about the minimum, maximum
11  * and average times for each operation.
12  */
13
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <unistd.h>
17
18 #include <yaz/zoom.h>
19
20
21 struct options {
22     int nconnect;               /* number of connections to make */
23     int nsearch;                /* number of searches on each connection */
24     int npresent;               /* number of presents for each search */
25     int full;                   /* 1 = fetch full records, 0 = brief */
26     int delay;                  /* number of ms to delay between ops */
27     int random;                 /* if true, delay is random 0-specified */
28 } options = {
29     3,
30     3,
31     3,
32     0,
33     1000,
34     1,
35 };
36
37
38 int main(int argc, char **argv)
39 {
40     char *host;
41     int port;
42     int c;
43
44     while ((c = getopt(argc, argv, "c:s:p:fbd:r")) != -1) {
45         switch (c) {
46         case 'c': options.nconnect = atoi(optarg); break;
47         case 's': options.nsearch = atoi(optarg); break;
48         case 'p': options.npresent = atoi(optarg); break;
49         case 'f': options.full = 1; break;
50         case 'b': options.full = 0; break;
51         case 'd': options.delay = atoi(optarg); break;
52         case 'r': options.random = 1; break;
53         default: goto USAGE;
54         }
55     }
56
57     if (argc-optind != 2) {
58     USAGE:
59         fprintf(stderr, "Usage: %s [options] <host> <port>\n"
60 "       -c <n>  Make <n> connection to the server [default: 3]\n"
61 "       -s <n>  Perform <n> searches on each connection [3]\n"
62 "       -p <n>  Make <n> present requests after each search [3]\n"
63 "       -f      Fetch full records [default: brief]\n"
64 "       -b      Fetch brief records\n"
65 "       -d <n>  Delay <n> ms after each operation\n"
66 "       -r      Delays are random between 0 and the specified number of ms\n"
67 , argv[0]);
68         return 1;
69     }
70
71     host = argv[optind];
72     port = atoi(argv[optind+1]);
73
74     return 0;
75 }