pub/, progs/: Implement Bernstein's Ed25519 signature scheme.
[catacomb] / progs / perftest.c
1 /* -*-c-*-
2 *
3 * Measure performance of various operations (Unix-specific)
4 *
5 * (c) 2004 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of Catacomb.
11 *
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
16 *
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * MA 02111-1307, USA.
26 */
27
28 /*----- Header files ------------------------------------------------------*/
29
30 #define _FILE_OFFSET_BITS 64
31
32 #include "config.h"
33
34 #include <errno.h>
35 #include <limits.h>
36 #include <math.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <stdlib.h>
40 #include <time.h>
41
42 #include <sys/types.h>
43 #include <sys/time.h>
44 #include <unistd.h>
45
46 #include <mLib/alloc.h>
47 #include <mLib/dstr.h>
48 #include <mLib/mdwopt.h>
49 #include <mLib/quis.h>
50 #include <mLib/report.h>
51 #include <mLib/sub.h>
52 #include <mLib/tv.h>
53
54 #include "rand.h"
55 #include "mp.h"
56 #include "mprand.h"
57 #include "fibrand.h"
58 #include "rsa.h"
59 #include "mpmont.h"
60 #include "mpbarrett.h"
61 #include "dh.h"
62 #include "pgen.h"
63 #include "ec.h"
64 #include "group.h"
65 #include "x25519.h"
66 #include "ed25519.h"
67
68 #include "cc.h"
69 #include "gcipher.h"
70 #include "ghash.h"
71 #include "gmac.h"
72 #include "poly1305.h"
73
74 #include "ectab.h"
75 #include "ptab.h"
76
77 /*----- Options -----------------------------------------------------------*/
78
79 typedef struct opts {
80 const char *name; /* Pre-configured named thing */
81 unsigned fbits; /* Field size bits */
82 unsigned gbits; /* Group size bits */
83 unsigned n; /* Number of factors */
84 unsigned i; /* Number of intervals (or zero) */
85 double t; /* Time for each interval (secs) */
86 unsigned f; /* Flags */
87 #define OF_NOCHECK 1u /* Don't do group checking */
88 } opts;
89
90 /*----- Job switch --------------------------------------------------------*/
91
92 /* --- Barrett exponentiation --- */
93
94 typedef struct bar_ctx {
95 size_t n;
96 mpbarrett b;
97 mp_expfactor *e;
98 } bar_ctx;
99
100 static void *bar_init(opts *o)
101 {
102 bar_ctx *c = CREATE(bar_ctx);
103 gprime_param gp;
104 qd_parse qd;
105 size_t i;
106
107 if (o->name) {
108 qd.p = o->name;
109 if (dh_parse(&qd, &gp))
110 die(1, "bad prime group: %s", qd.e);
111 } else {
112 if (!o->fbits) o->fbits = 1024;
113 dh_gen(&gp, o->gbits, o->fbits, 0, &rand_global, pgen_evspin, 0);
114 }
115 mpbarrett_create(&c->b, gp.p);
116 if (!o->n) o->n = 1;
117 c->n = o->n;
118 c->e = xmalloc(c->n * sizeof(group_expfactor));
119 for (i = 0; i < c->n; i++) {
120 c->e[i].base = mprand_range(MP_NEW, gp.p, &rand_global, 0);
121 c->e[i].exp = mprand_range(MP_NEW, gp.q, &rand_global, 0);
122 }
123 dh_paramfree(&gp);
124 return (c);
125 }
126
127 static void bar_run(void *cc)
128 {
129 bar_ctx *c = cc;
130 mp *d = mpbarrett_exp(&c->b, MP_NEW, c->e[0].base, c->e[0].exp);
131 MP_DROP(d);
132 }
133
134 static void barsim_run(void *cc)
135 {
136 bar_ctx *c = cc;
137 mp *d = mpbarrett_mexp(&c->b, MP_NEW, c->e, c->n);
138 MP_DROP(d);
139 }
140
141 /* --- Montgomery exponentiation --- */
142
143 typedef struct mont_ctx {
144 size_t n;
145 mpmont m;
146 mp_expfactor *e;
147 } mont_ctx;
148
149 static void *mont_init(opts *o)
150 {
151 mont_ctx *c = CREATE(mont_ctx);
152 gprime_param gp;
153 qd_parse qd;
154 size_t i;
155
156 if (o->name) {
157 qd.p = o->name;
158 if (dh_parse(&qd, &gp))
159 die(1, "bad prime group: %s", qd.e);
160 } else {
161 if (!o->fbits) o->fbits = 1024;
162 dh_gen(&gp, o->gbits, o->fbits, 0, &rand_global, pgen_evspin, 0);
163 }
164 mpmont_create(&c->m, gp.p);
165 if (!o->n) o->n = 1;
166 c->n = o->n;
167 c->e = xmalloc(c->n * sizeof(mp_expfactor));
168 for (i = 0; i < c->n; i++) {
169 c->e[i].base = mprand_range(MP_NEW, gp.p, &rand_global, 0);
170 c->e[i].exp = mprand_range(MP_NEW, gp.q, &rand_global, 0);
171 }
172 dh_paramfree(&gp);
173 return (c);
174 }
175
176 static void mont_run(void *cc)
177 {
178 mont_ctx *c = cc;
179 mp *d = mpmont_expr(&c->m, MP_NEW, c->e[0].base, c->e[0].exp);
180 MP_DROP(d);
181 }
182
183 static void montsim_run(void *cc)
184 {
185 mont_ctx *c = cc;
186 mp *d = mpmont_mexpr(&c->m, MP_NEW, c->e, c->n);
187 MP_DROP(d);
188 }
189
190 /* --- Group exponentiation --- */
191
192 typedef struct gr_ctx {
193 size_t n;
194 group *g;
195 group_expfactor *e;
196 } gr_ctx;
197
198 static void *grp_init(opts *o)
199 {
200 gr_ctx *c = CREATE(gr_ctx);
201 const char *e;
202 gprime_param gp;
203 qd_parse qd;
204 size_t i;
205
206 if (o->name) {
207 qd.p = o->name;
208 if (dh_parse(&qd, &gp))
209 die(1, "bad prime group: %s", qd.e);
210 } else {
211 if (!o->fbits) o->fbits = 1024;
212 dh_gen(&gp, o->gbits, o->fbits, 0, &rand_global, pgen_evspin, 0);
213 }
214 c->g = group_prime(&gp);
215 if (!(o->f & OF_NOCHECK) && (e = G_CHECK(c->g, &rand_global)) != 0)
216 die(1, "bad group: %s", e);
217 if (!o->n) o->n = 1;
218 c->n = o->n;
219 c->e = xmalloc(c->n * sizeof(group_expfactor));
220 for (i = 0; i < c->n; i++) {
221 c->e[i].base = G_CREATE(c->g);
222 G_FROMINT(c->g, c->e[i].base,
223 mprand_range(MP_NEW, gp.p, &rand_global, 0));
224 c->e[i].exp = mprand_range(MP_NEW, gp.q, &rand_global, 0);
225 }
226 dh_paramfree(&gp);
227 return (c);
228 }
229
230 static void *grec_init(opts *o)
231 {
232 gr_ctx *c = CREATE(gr_ctx);
233 const char *e;
234 ec_info ei;
235 ec p = EC_INIT;
236 size_t i;
237
238 if (!o->name)
239 die(1, "can't generate elliptic curves");
240 if ((e = ec_getinfo(&ei, o->name)) != 0)
241 die(1, "bad curve: %s", e);
242 c->g = group_ec(&ei);
243 if (!(o->f & OF_NOCHECK) && (e = G_CHECK(c->g, &rand_global)) != 0)
244 die(1, "bad group: %s", e);
245 if (!o->n) o->n = 1;
246 c->n = o->n;
247 c->e = xmalloc(c->n * sizeof(group_expfactor));
248 for (i = 0; i < c->n; i++) {
249 c->e[i].base = G_CREATE(c->g);
250 ec_rand(ei.c, &p, &rand_global);
251 G_FROMEC(c->g, c->e[i].base, &p);
252 c->e[i].exp = mprand_range(MP_NEW, ei.r, &rand_global, 0);
253 }
254 EC_DESTROY(&p);
255 return (c);
256 }
257
258 static void gr_run(void *cc)
259 {
260 gr_ctx *c = cc;
261 ge *x = G_CREATE(c->g);
262 G_EXP(c->g, x, c->e[0].base, c->e[0].exp);
263 G_DESTROY(c->g, x);
264 }
265
266 static void grsim_run(void *cc)
267 {
268 gr_ctx *c = cc;
269 ge *x = G_CREATE(c->g);
270 G_MEXP(c->g, x, c->e, c->n);
271 G_DESTROY(c->g, x);
272 }
273
274 /* --- x25519 --- */
275
276 typedef struct x25519_jobctx {
277 octet k[X25519_KEYSZ];
278 octet p[X25519_PUBSZ];
279 } x25519_jobctx;
280
281 static void *x25519_jobinit(opts *o)
282 {
283 x25519_jobctx *c = CREATE(x25519_jobctx);
284 rand_get(RAND_GLOBAL, c->k, sizeof(c->k));
285 rand_get(RAND_GLOBAL, c->p, sizeof(c->p));
286 return (c);
287 }
288
289 static void x25519_jobrun(void *cc)
290 { x25519_jobctx *c = cc; octet z[X25519_OUTSZ]; x25519(z, c->k, c->p); }
291
292 /* --- Ed25519 --- */
293
294 typedef struct ed25519_signctx {
295 octet k[ED25519_KEYSZ];
296 octet K[ED25519_PUBSZ];
297 octet m[64];
298 } ed25519_signctx;
299
300 typedef struct ed25519_vrfctx {
301 octet K[ED25519_PUBSZ];
302 octet m[64];
303 octet sig[ED25519_SIGSZ];
304 } ed25519_vrfctx;
305
306 static void *ed25519_signinit(opts *o)
307 {
308 ed25519_signctx *c = CREATE(ed25519_signctx);
309
310 rand_get(RAND_GLOBAL, c->k, sizeof(c->k));
311 rand_get(RAND_GLOBAL, c->m, sizeof(c->m));
312 ed25519_pubkey(c->K, c->k, sizeof(c->k));
313 return (c);
314 }
315
316 static void ed25519_signrun(void *cc)
317 {
318 ed25519_signctx *c = cc;
319 octet sig[ED25519_SIGSZ];
320
321 ed25519_sign(sig, c->k, sizeof(c->k), c->K, c->m, sizeof(c->m));
322 }
323
324 static void *ed25519_vrfinit(opts *o)
325 {
326 octet k[ED25519_KEYSZ];
327 ed25519_vrfctx *c = CREATE(ed25519_vrfctx);
328
329 rand_get(RAND_GLOBAL, k, sizeof(k));
330 rand_get(RAND_GLOBAL, c->m, sizeof(c->m));
331 ed25519_pubkey(c->K, k, sizeof(k));
332 ed25519_sign(c->sig, k, sizeof(k), c->K, c->m, sizeof(c->m));
333 return (c);
334 }
335
336 static void ed25519_vrfrun(void *cc)
337 {
338 ed25519_vrfctx *c = cc;
339 ed25519_verify(c->K, c->m, sizeof(c->m), c->sig);
340 }
341
342 /* --- RSA --- */
343
344 typedef struct rsapriv_ctx {
345 rsa_priv rp;
346 rsa_privctx rpc;
347 mp *m;
348 } rsapriv_ctx;
349
350 static void *rsapriv_init(opts *o)
351 {
352 rsapriv_ctx *c = CREATE(rsapriv_ctx);
353
354 if (!o->fbits) o->fbits = 1024;
355 rsa_gen(&c->rp, o->fbits, &rand_global, 0, pgen_evspin, 0);
356 rsa_privcreate(&c->rpc, &c->rp, 0);
357 c->m = mprand_range(MP_NEW, c->rp.n, &rand_global, 0);
358 return (c);
359 }
360
361 static void *rsaprivblind_init(opts *o)
362 {
363 rsapriv_ctx *c = CREATE(rsapriv_ctx);
364
365 if (!o->fbits) o->fbits = 1024;
366 rsa_gen(&c->rp, o->fbits, &rand_global, 0, pgen_evspin, 0);
367 rsa_privcreate(&c->rpc, &c->rp, fibrand_create(0));
368 c->m = mprand_range(MP_NEW, c->rp.n, &rand_global, 0);
369 return (c);
370 }
371
372 static void rsapriv_run(void *cc)
373 {
374 rsapriv_ctx *c = cc;
375 mp *d = rsa_privop(&c->rpc, MP_NEW, c->m);
376 MP_DROP(d);
377 }
378
379 typedef struct rsapub_ctx {
380 rsa_pub rp;
381 rsa_pubctx rpc;
382 mp *m;
383 } rsapub_ctx;
384
385 static void *rsapub_init(opts *o)
386 {
387 rsapub_ctx *c = CREATE(rsapub_ctx);
388 rsa_priv rp;
389
390 if (!o->fbits) o->fbits = 1024;
391 rsa_gen(&rp, o->fbits, &rand_global, 0, pgen_evspin, 0);
392 c->rp.n = MP_COPY(rp.n);
393 c->rp.e = MP_COPY(rp.e);
394 rsa_privfree(&rp);
395 rsa_pubcreate(&c->rpc, &c->rp);
396 c->m = mprand_range(MP_NEW, c->rp.n, &rand_global, 0);
397 return (c);
398 }
399
400 static void rsapub_run(void *cc)
401 {
402 rsapub_ctx *c = cc;
403 mp *d = rsa_pubop(&c->rpc, MP_NEW, c->m);
404 MP_DROP(d);
405 }
406
407 /* --- Symmetric encryption --- */
408
409 typedef struct ksched_ctx {
410 const gccipher *c;
411 octet *k;
412 size_t ksz;
413 } ksched_ctx;
414
415 static void *ksched_init(opts *o)
416 {
417 ksched_ctx *c = CREATE(ksched_ctx);
418 if (!o->name)
419 die(1, "must specify encryption scheme name");
420 if ((c->c = gcipher_byname(o->name)) == 0)
421 die(1, "encryption scheme `%s' not known", o->name);
422 c->ksz = keysz(o->gbits/8, c->c->keysz);
423 c->k = xmalloc(c->ksz);
424 rand_get(RAND_GLOBAL, c->k, c->ksz);
425 return (c);
426 }
427
428 static void ksched_run(void *cc)
429 {
430 ksched_ctx *c = cc;
431 gcipher *gc = GC_INIT(c->c, c->k, c->ksz);
432 GC_DESTROY(gc);
433 }
434
435 typedef struct enc_ctx {
436 gcipher *c;
437 octet *m;
438 size_t sz;
439 size_t n;
440 } enc_ctx;
441
442 static void *enc_init(opts *o)
443 {
444 enc_ctx *c = CREATE(enc_ctx);
445 const gccipher *cc;
446 size_t ksz;
447 octet *k;
448 if (!o->name)
449 die(1, "must specify encryption scheme name");
450 if ((cc = gcipher_byname(o->name)) == 0)
451 die(1, "encryption scheme `%s' not known", o->name);
452 ksz = keysz(0, cc->keysz);
453 k = xmalloc(ksz);
454 rand_get(RAND_GLOBAL, k, ksz);
455 c->c = GC_INIT(cc, k, ksz);
456 xfree(k);
457 c->sz = o->gbits ? o->gbits : 65536;
458 c->n = o->n ? o->n : 16;
459 c->m = xmalloc(c->sz);
460 return (c);
461 }
462
463 static void enc_run(void *cc)
464 {
465 enc_ctx *c = cc;
466 size_t i;
467 for (i = 0; i < c->n; i++)
468 GC_ENCRYPT(c->c, c->m, c->m, c->sz);
469 }
470
471 /* --- Hashing --- */
472
473 typedef struct hash_ctx {
474 const gchash *h;
475 octet *m;
476 size_t sz;
477 size_t n;
478 } hash_ctx;
479
480 static void *hash_init(opts *o)
481 {
482 hash_ctx *c = CREATE(hash_ctx);
483 if (!o->name)
484 die(1, "must specify hash function name");
485 if ((c->h = ghash_byname(o->name)) == 0)
486 die(1, "hash function `%s' not known", o->name);
487 c->sz = o->gbits ? o->gbits : 65536;
488 c->n = o->n ? o->n : 16;
489 c->m = xmalloc(c->sz);
490 return (c);
491 }
492
493 static void hash_run(void *cc)
494 {
495 hash_ctx *c = cc;
496 size_t i;
497 ghash *h = GH_INIT(c->h);
498 for (i = 0; i < c->n; i++)
499 GH_HASH(h, c->m, c->sz);
500 GH_DONE(h, 0);
501 GH_DESTROY(h);
502 }
503
504 /* --- Poly1305 --- */
505
506 typedef struct poly1305_jobctx {
507 poly1305_key k;
508 octet s[POLY1305_MASKSZ];
509 octet *m;
510 size_t sz;
511 size_t n;
512 } poly1305_jobctx;
513
514 static void *poly1305_jobinit(opts *o)
515 {
516 octet k[POLY1305_KEYSZ];
517 poly1305_jobctx *c = CREATE(poly1305_jobctx);
518 rand_get(RAND_GLOBAL, k, sizeof(k));
519 poly1305_keyinit(&c->k, k, sizeof(k));
520 rand_get(RAND_GLOBAL, c->s, sizeof(c->s));
521 c->sz = o->gbits ? o->gbits : 65536;
522 c->n = o->n ? o->n : 16;
523 c->m = xmalloc(c->sz);
524 return (c);
525 }
526
527 static void poly1305_jobrun(void *cc)
528 {
529 poly1305_jobctx *c = cc;
530 poly1305_ctx ctx;
531 octet t[POLY1305_TAGSZ];
532 size_t i;
533 poly1305_macinit(&ctx, &c->k, c->s);
534 for (i = 0; i < c->n; i++) poly1305_hash(&ctx, c->m, c->sz);
535 poly1305_done(&ctx, t);
536 }
537
538 /* --- Job table --- */
539
540 typedef struct jobops {
541 const char *name;
542 void *(*init)(opts *);
543 void (*run)(void *);
544 } jobops;
545
546 static const jobops jobtab[] = {
547 { "g-prime-exp", grp_init, gr_run },
548 { "g-ec-mul", grec_init, gr_run },
549 { "g-prime-exp-sim", grp_init, grsim_run },
550 { "g-ec-mul-sim", grec_init, grsim_run },
551 { "barrett-exp", bar_init, bar_run },
552 { "barrett-exp-sim", bar_init, barsim_run },
553 { "mont-exp", mont_init, mont_run },
554 { "mont-exp-sim", mont_init, montsim_run },
555 { "rsa-priv", rsapriv_init, rsapriv_run },
556 { "rsa-priv-blind", rsaprivblind_init, rsapriv_run },
557 { "rsa-pub", rsapub_init, rsapub_run },
558 { "x25519", x25519_jobinit, x25519_jobrun },
559 { "ed25519-sign", ed25519_signinit, ed25519_signrun },
560 { "ed25519-vrf", ed25519_vrfinit, ed25519_vrfrun },
561 { "ksched", ksched_init, ksched_run },
562 { "enc", enc_init, enc_run },
563 { "hash", hash_init, hash_run },
564 { "poly1305", poly1305_jobinit, poly1305_jobrun },
565 { 0, 0, 0 }
566 };
567
568 /*----- Main code ---------------------------------------------------------*/
569
570 void version(FILE *fp)
571 {
572 pquis(fp, "$, Catacomb " VERSION "\n");
573 }
574
575 static void usage(FILE *fp)
576 {
577 pquis(fp, "Usage: $ [-options] job\n");
578 }
579
580 static void help(FILE *fp)
581 {
582 version(fp);
583 putc('\n', fp);
584 usage(fp);
585 pquis(fp, "\n\
586 Various performance tests.\n\
587 \n\
588 Options:\n\
589 \n\
590 -h, --help Show this help text.\n\
591 -v, --version Show program version number.\n\
592 -u, --usage Show terse usage message.\n\
593 -l, --list [ITEM...] List all the various names of things.\n\
594 \n\
595 -C, --name=NAME Select curve/DH-group/enc/hash name.\n\
596 -b, --field-bits Field size for g-prime and rsa.\n\
597 -q, --no-check Don't check field/group for validity.\n\
598 -B, --group-bits Group size for g-prime; key size for ksched;\n\
599 data size for enc and hash.\n\
600 -n, --factors=COUNT Number of factors for {exp,mul}-sim.\n\
601 -i, --intervals=COUNT Number of intervals to run for. [0; forever]\n\
602 -t, --time=TIME Length of an interval in seconds. [1]\n\
603 ");
604 }
605
606 #define LISTS(LI) \
607 LI("Lists", list, \
608 listtab[i].name, listtab[i].name) \
609 LI("Jobs", job, \
610 jobtab[i].name, jobtab[i].name) \
611 LI("Elliptic curves", ec, \
612 ectab[i].name, ectab[i].name) \
613 LI("Diffie-Hellman groups", dh, \
614 ptab[i].name, ptab[i].name) \
615 LI("Encryption algorithms", cipher, \
616 gciphertab[i], gciphertab[i]->name) \
617 LI("Hash functions", hash, \
618 ghashtab[i], ghashtab[i]->name)
619
620 MAKELISTTAB(listtab, LISTS)
621
622 static unsigned uarg(const char *what, const char *p)
623 {
624 char *q;
625 unsigned long u;
626 errno = 0;
627 u = strtoul(p, &q, 0);
628 if (*q || u > UINT_MAX || q == p || errno)
629 die(1, "bad %s `%s'", what, p);
630 return (u);
631 }
632
633 static double farg(const char *what, const char *p)
634 {
635 char *q;
636 double f;
637 errno = 0;
638 f = strtod(p, &q);
639 if (*q || q == p || errno)
640 die(1, "bad %s `%s'", what, p);
641 return (f);
642 }
643
644 int main(int argc, char *argv[])
645 {
646 int i;
647 opts o = { 0 };
648 const jobops *j;
649 struct timeval tv_next, tv_now;
650 double t, ttot;
651 unsigned n;
652 unsigned long ii;
653 clock_t c_start, c_stop;
654 double itot;
655 void *p;
656
657 ego(argv[0]);
658 o.t = 1;
659 for (;;) {
660 static const struct option opts[] = {
661 { "help", 0, 0, 'h' },
662 { "version", 0, 0, 'v' },
663 { "usage", 0, 0, 'u' },
664 { "list", 0, 0, 'l' },
665 { "name", OPTF_ARGREQ, 0, 'C' },
666 { "field-bits", OPTF_ARGREQ, 0, 'b' },
667 { "group-bits", OPTF_ARGREQ, 0, 'B' },
668 { "factors", OPTF_ARGREQ, 0, 'n' },
669 { "intervals", OPTF_ARGREQ, 0, 'i' },
670 { "time", OPTF_ARGREQ, 0, 't' },
671 { "no-check", 0, 0, 'q' },
672 { 0, 0, 0, 0 }
673 };
674
675 i = mdwopt(argc, argv, "hvulC:b:B:n:i:t:q", opts, 0, 0, 0);
676 if (i < 0) break;
677 switch (i) {
678 case 'h': help(stdout); exit(0);
679 case 'v': version(stdout); exit(0);
680 case 'u': usage(stdout); exit(0);
681 case 'l': exit(displaylists(listtab, argv + optind));
682 case 'C': o.name = optarg; break;
683 case 'b': o.fbits = uarg("field bits", optarg); break;
684 case 'B': o.gbits = uarg("subgroup bits", optarg); break;
685 case 'n': o.n = uarg("factor count", optarg); break;
686 case 'i': o.i = uarg("interval count", optarg); break;
687 case 't': o.t = farg("interval length", optarg); break;
688 case 'q': o.f |= OF_NOCHECK; break;
689 default: usage(stderr); exit(1);
690 }
691 }
692 if (optind + 1 != argc) { usage(stderr); exit(1); }
693
694 for (j = jobtab; j->name; j++)
695 if (strcmp(j->name, argv[optind]) == 0) break;
696 if (!j->name) die(1, "unknown job type `%s'", argv[optind]);
697 p = j->init(&o);
698
699 n = 0;
700 ttot = itot = 0;
701 gettimeofday(&tv_now, 0);
702 do {
703 tv_addl(&tv_next, &tv_now, o.t, fmod(o.t * MILLION, MILLION));
704 ii = 0;
705 c_start = clock();
706 do {
707 j->run(p);
708 ii++;
709 gettimeofday(&tv_now, 0);
710 } while (TV_CMP(&tv_now, <, &tv_next));
711 c_stop = clock();
712 t = (double)(c_stop - c_start)/CLOCKS_PER_SEC;
713 itot += ii;
714 ttot += t;
715 printf("%5u: did = %5lu; /sec = %5f; avg /sec = %5f\n",
716 n, ii, ii/t, itot/ttot);
717 fflush(stdout);
718 n++;
719 } while (!o.i || n < o.i);
720
721 return (0);
722 }
723
724 /*----- That's all, folks -------------------------------------------------*/