Option parsing. Still no functionality.
[yaz-moved-to-github.git] / util / benchmark.c
1 /* $Id: benchmark.c,v 1.2 2003-12-24 16:59:12 mike Exp $
2  * Copyright (C) 2003 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 <stdio.h>
15 #include <unistd.h>
16
17 #include <yaz/zoom.h>
18
19
20 struct options {
21     int nconnect;               /* number of connections to make */
22     int nsearch;                /* number of searches on each connection */
23     int npresent;               /* number of presents for each search */
24     int full;                   /* 1 = fetch full records, 0 = brief */
25     int delay;                  /* number of ms to delay between ops */
26     int random;                 /* if true, delay is random 0-specified */
27 } options = {
28     3,
29     3,
30     3,
31     0,
32     1000,
33     1,
34 };
35
36
37 int main(int argc, char **argv)
38 {
39     char *host;
40     int port;
41     int c;
42
43     while ((c = getopt(argc, argv, "c:s:p:fbd:r")) != -1) {
44         switch (c) {
45         case 'c': options.nconnect = atoi(optarg); break;
46         case 's': options.nsearch = atoi(optarg); break;
47         case 'p': options.npresent = atoi(optarg); break;
48         case 'f': options.full = 1; break;
49         case 'b': options.full = 0; break;
50         case 'd': options.delay = atoi(optarg); break;
51         case 'r': options.random = 1; break;
52         default: goto USAGE;
53         }
54     }
55
56     if (argc-optind != 2) {
57     USAGE:
58         fprintf(stderr, "Usage: %s [options] <host> <port>\n"
59 "       -c <n>  Make <n> connection to the server [default: 3]\n"
60 "       -s <n>  Perform <n> searches on each connection [3]\n"
61 "       -p <n>  Make <n> present requests after each search [3]\n"
62 "       -f      Fetch full records [default: brief]\n"
63 "       -b      Fetch brief records\n"
64 "       -d <n>  Delay <n> ms after each operation\n"
65 "       -r      Delays are random between 0 and the specified number of ms\n"
66 , argv[0]);
67         return 1;
68     }
69
70     host = argv[optind];
71     port = atoi(argv[optind+1]);
72
73     return 0;
74 }