regex bench from libc-bench
authornsz <nsz@port70.net>
Fri, 5 Aug 2011 00:11:37 +0000 (02:11 +0200)
committernsz <nsz@port70.net>
Fri, 5 Aug 2011 00:11:37 +0000 (02:11 +0200)
src/regex/bench.c [new file with mode: 0644]

diff --git a/src/regex/bench.c b/src/regex/bench.c
new file mode 100644 (file)
index 0000000..3f911ca
--- /dev/null
@@ -0,0 +1,42 @@
+#define _POSIX_C_SOURCE 200809L
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <regex.h>
+#include <locale.h>
+#include "test.h"
+
+
+void bench_regex_compile(int N) {
+       regex_t re;
+       int i;
+
+       setlocale(LC_CTYPE, "");
+       for (i=0; i<N; i++) {
+               regcomp(&re, "(a|b|c)*d*b", REG_EXTENDED);
+               regfree(&re);
+       }
+}
+
+static void regex_search(int N, char *s) {
+       char buf[100000];
+       regex_t re;
+       int i;
+
+       setlocale(LC_CTYPE, "");
+       memset(buf, 'a', sizeof(buf)-2);
+       buf[sizeof buf - 2] = 'b';
+       buf[sizeof buf - 1] = 0;
+       regcomp(&re, s, REG_EXTENDED);
+       for (i=0; i<N; i++)
+               regexec(&re, buf, 0, 0, 0);
+       regfree(&re);
+}
+
+void bench_regex_search1(int N) {
+       regex_search(N, "(a|b|c)*d*b");
+}
+
+void bench_regex_search2(int N) {
+       regex_search(N, "a{25}b");
+}