2 * Simple timing program for regcomp().
4 * Copyright (c) 1986 by University of Toronto.
5 * Written by Henry Spencer. Not derived from licensed software.
7 * Permission is granted to anyone to use this software for any
8 * purpose on any computer system, and to redistribute it freely,
9 * subject to the following restrictions:
11 * 1. The author is not responsible for the consequences of use of
12 * this software, no matter how awful, even if they arise
15 * 2. The origin of this software must not be misrepresented, either
16 * by explicit claim or by omission.
18 * 3. Altered versions must be plainly marked as such, and must not
19 * be misrepresented as being the original software.
21 * Usage: timer ncomp nexec nsub
23 * timer ncomp nexec nsub regexp string [ answer [ sub ] ]
25 * The second form is for timing repetitions of a single test case.
26 * The first form's test data is a compiled-in copy of the "tests" file.
27 * Ncomp, nexec, nsub are how many times to do each regcomp, regexec,
28 * and regsub. The way to time an operation individually is to do something
29 * like "timer 1 50 1".
34 char *re
, *str
, *ans
, *src
, *dst
;
37 { NULL
, NULL
, NULL
, NULL
, NULL
}
42 int errreport
= 0; /* Report errors via errseen? */
43 char *errseen
= NULL
; /* Error message. */
52 int ncomp
, nexec
, nsub
;
61 ncomp
= atoi(argv
[1]);
62 nexec
= atoi(argv
[2]);
82 try(one
, ncomp
, nexec
, nsub
);
84 multiple(ncomp
, nexec
, nsub
);
103 fprintf(stderr
, "regexp: ");
104 fprintf(stderr
, s1
, s2
);
105 fprintf(stderr
, "\n");
112 multiple(ncomp
, nexec
, nsub
)
113 int ncomp
, nexec
, nsub
;
116 extern char *strchr();
119 for (i
= 0; tests
[i
].re
!= NULL
; i
++) {
121 try(tests
[i
], ncomp
, nexec
, nsub
);
125 try(fields
, ncomp
, nexec
, nsub
)
127 int ncomp
, nexec
, nsub
;
134 r
= regcomp(fields
.re
);
136 if (*fields
.ans
!= 'c')
137 complain("regcomp failure in `%s'", fields
.re
);
140 if (*fields
.ans
== 'c') {
141 complain("unexpected regcomp success in `%s'", fields
.re
);
145 for (i
= ncomp
-1; i
> 0; i
--) {
147 r
= regcomp(fields
.re
);
149 if (!regexec(r
, fields
.str
)) {
150 if (*fields
.ans
!= 'n')
151 complain("regexec failure in `%s'", "");
155 if (*fields
.ans
== 'n') {
156 complain("unexpected regexec success", "");
160 for (i
= nexec
-1; i
> 0; i
--)
161 (void) regexec(r
, fields
.str
);
163 for (i
= nsub
; i
> 0; i
--)
164 regsub(r
, fields
.src
, dbuf
);
165 if (errseen
!= NULL
) {
166 complain("regsub complaint", "");
170 if (strcmp(dbuf
, fields
.dst
) != 0)
171 complain("regsub result `%s' wrong", dbuf
);
179 fprintf(stderr
, "try: %d: ", lineno
);
180 fprintf(stderr
, s1
, s2
);
181 fprintf(stderr
, " (%s)\n", (errseen
!= NULL
) ? errseen
: "");