use _POSIX_C_SOURCE in cflags, use CLOCK_REALTIME in b and add -v flag to t
[libc-test] / src / regex / bench.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <regex.h>
5 #include <locale.h>
6 #include "test.h"
7
8
9 void bench_regex_compile(int N) {
10         regex_t re;
11         int i;
12
13         setlocale(LC_CTYPE, "");
14         for (i=0; i<N; i++) {
15                 regcomp(&re, "(a|b|c)*d*b", REG_EXTENDED);
16                 regfree(&re);
17         }
18 }
19
20 static void regex_search(int N, char *s) {
21         char buf[100000];
22         regex_t re;
23         int i;
24
25         setlocale(LC_CTYPE, "");
26         memset(buf, 'a', sizeof(buf)-2);
27         buf[sizeof buf - 2] = 'b';
28         buf[sizeof buf - 1] = 0;
29         regcomp(&re, s, REG_EXTENDED);
30         for (i=0; i<N; i++)
31                 regexec(&re, buf, 0, 0, 0);
32         regfree(&re);
33 }
34
35 void bench_regex_search1(int N) {
36         regex_search(N, "(a|b|c)*d*b");
37 }
38
39 void bench_regex_search2(int N) {
40         regex_search(N, "a{25}b");
41 }