-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrrex3.c
79 lines (69 loc) · 2.44 KB
/
rrex3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#define RREX3_DEBUG 1
#include "rrex3.h"
#include "rlib.h"
#include <regex.h>
void benchmark(int times, char *str, char *expr) {
regmatch_t matches[10];
printf("Matching \"%s\" with \"%s\".\n", str, expr);
regex_t regex;
if (regcomp(®ex, expr, REG_EXTENDED)) {
printf("Creg: error in regular expression.\n");
exit(1);
}
printf("creg: ");
RBENCH(times, {
if (regexec(®ex, str, 0, matches, 0)) {
printf("Creg: error executing regular expression.\n");
}
})
regfree(®ex);
;
rrex3_t *rrex = rrex3_compile(NULL, expr);
printf("rrex3 (%s): ", rrex->compiled);
RBENCH(times, {
if (rrex3(rrex, str, NULL)) {
} else {
printf("Rrex3: error\n");
exit(0);
}
});
rrex3_free(rrex);
printf("\n");
}
int main() {
rrex3_test();
int times = 1;
benchmark(times, "\"stdio.h\"\"string.h\"\"sys/time.h\"",
"\".*\"\".*\"\".*\"");
benchmark(times, "abcdefghijklmnopqrstuvwxyz",
"abcdefghijklmnopqrstuvwxyz$");
benchmark(times, "aaaaaaaaaaaaaaaaaaaaaaaaaa",
"aaaaaaaaaaaaaaaaaaaaaaaaaa$");
benchmark(times, "abcdefghijklmnopqrstuvwxyz",
"..........................$");
// [abcm] failed
benchmark(times, "abcdefghijklmnopqrstuvwxyz", ".*z");
benchmark(times, "abcde", ".*e");
benchmark(times, "abcdef", ".*f");
benchmark(times, "abcdefghijklmnopqrstuvwxyz",
"[a]b*c+d\\w[f-g][g][h-i][i][^a][abcdefgk][l][m][n][o][p][a-z][r]"
"[s][t][u][v][w].*z$");
benchmark(times, "zzz",
"[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]["
"abcdefghijklmnopqrstuvwxyz]$");
benchmark(times, "7245 Sr", "[0-9][0-9][0-9][0-9] ?\\w\\w$");
benchmark(times,
"abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmn"
"opqrstuvwxyzesting",
"[z-z][e-e]");
benchmark(times,
"abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmn"
"opqrstuvwxyzesting",
"zesting");
benchmark(times, "\"stdio.h\"\"string.h\"\"sys/time.h\"",
"\"(.*)\"\"(.*)\"\"(.*)\"");
benchmark(times, " \"stdio.h\"\"string.h\"\"sys/time.h\"",
"\".+\"\".+\"\".+\"");
benchmark(times, " \"stdio.h\"\"string.h\"\"sys/time.h\"",
"\"(.+)\"\"(.+)\"\"(.+)\"");
}