From 3803bbbd9dcb65e3299a72e1f2ab6e60dc6eef39 Mon Sep 17 00:00:00 2001 From: anon Date: Sat, 9 Sep 2023 16:28:16 +0200 Subject: [PATCH] brenchmarking WIP --- .gitignore | 1 + benchmark/Makefile | 23 ++++++++++++ benchmark/gnu_racer.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++ benchmark/jeger_racer.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 196 insertions(+) create mode 100644 benchmark/Makefile create mode 100644 benchmark/gnu_racer.cpp create mode 100644 benchmark/jeger_racer.cpp diff --git a/.gitignore b/.gitignore index ef00294..1545471 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ regtest *.out +*.so .gdb_history diff --git a/benchmark/Makefile b/benchmark/Makefile new file mode 100644 index 0000000..da12428 --- /dev/null +++ b/benchmark/Makefile @@ -0,0 +1,23 @@ +DEBUG := 0 + +BUILD.cpp := ${CXX} ${CXXFLAGS} ${CPPFLAGS} + +.ONESHELL: + +test: build + for $$i i *.out; + do time $$i + done + +build: jeger gnu + +jeger: ../source/vector.c ../source/jeger.c jeger_racer.cpp + gcc -shared ../source/vector.c -o vector.so + gcc -shared ../source/jeger.c -o jeger.so + ${BUILD.cpp} -I../source/ vector.so jeger.so jeger_racer.cpp -o jeger_racer.out + +gnu: gnu_racer.cpp + ${BUILD.cpp} gnu_racer.cpp -o gnu_racer.out + +clean: + rm *.so *.out diff --git a/benchmark/gnu_racer.cpp b/benchmark/gnu_racer.cpp new file mode 100644 index 0000000..f8342e0 --- /dev/null +++ b/benchmark/gnu_racer.cpp @@ -0,0 +1,89 @@ +#include + +static +void TEST(const char * const what, + const char * const on, + const bool expect){ + + regex_t * r = regcomp(&r, pattern, REG_EXTENDED | REG_NOSUB); + int result = regexec(regex, input, 0, NULL, 0); + regfree(r); + +#if DEBUG + assert((result != -1) && (expect == (bool)result)); +#endif +} + +signed main(){ + TEST( R"del(abc)del", "abc", true); + TEST(R"del(efg1)del", "efg1", true); + TEST( R"del(nig)del", "ger", false); + TEST( R"del(ss)del", "sss", true); + TEST( R"del(sss)del", "ss", false); + + TEST( R"del(ab\+c)del", "abc", true); + TEST(R"del(ef\+g1)del", "effffg1", true); + TEST(R"del(efg1\+)del", "efg", false); + TEST(R"del(efg1\+)del", "efg1", true); + TEST(R"del(efg1\+)del", "efg11", true); + + TEST( R"del(a\+a)del", "aaa", true); + TEST( R"del(a\+a)del", "aa", true); + TEST( R"del(a\+a)del", "a", false); + TEST( R"del(a\+a)del", "aaa", true); + TEST(R"del(a\++)del", "aaa", false); + + TEST( R"del(ab*c)del", "abc", true); + TEST(R"del(ef*g1)del", "effffg1", true); + TEST(R"del(efg1*)del", "efg", true); + TEST(R"del(efg1*)del", "efg1", true); + TEST(R"del(efg1*)del", "efg11", true); + + TEST( R"del(ne.)del", "net", true); + TEST( R"del(ne.)del", "ne", false); + TEST(R"del(ne.\+)del", "neoo", true); + TEST(R"del(ne.*)del", "neoo", true); + TEST(R"del(ne.*)del", "ne", true); + + TEST( R"del(ne.o)del", "neto", true); + TEST(R"del(ne.\+o)del", "nettto", true); + TEST(R"del(ne.\+o)del", "neo", false); + TEST(R"del(ne.\+o)del", "neoo", true); + TEST(R"del(ne.*o)del", "neo", true); + + TEST(R"del(ne.)del", "ne\t", true); + TEST(R"del(ne\t)del", "ne", false); + TEST(R"del(ne\t)del", "ne\t", true); + TEST(R"del(ne\t)del", "net", false); + TEST(R"del(ne)del", "ne\t", true); + + TEST(R"del(\sa)del", " a", true); + TEST(R"del(\sa)del", " a ", true); + TEST(R"del(\wi)del", "hi", true); + TEST(R"del(\w\+)del", "asd", true); + TEST(R"del(\w*)del", "", true); + + TEST( R"del([A-Za-z]+)del", "HelloWorld", true); + TEST(R"del([A-Za-z]+g)del", "HelloWorldg", true); + TEST(R"del([A-Za-z]+g)del", "g", false); + TEST(R"del([A-Za-z]*g)del", "g", true); + TEST(R"del([A-Za-z]+1)del", "1", false); + + TEST( R"del([^0-9])del", "0", false); + TEST( R"del([^A-Za-z])del", "HelloWorld", false); + TEST(R"del([^A-Za-z]+g)del", "313g", true); + TEST( R"del([^0-9])del", "HelloWorld", true); + TEST( R"del([^a])del", "ba", true); + + TEST( R"del(^\^)del", "^^", true); + TEST( R"del(^\^)del", " ^", false); + TEST(R"del(^ \^)del", " ^", true); + TEST( R"del(^a*)del", "asd", true); + TEST( R"del(^)del", "", true); + + TEST( R"del(\)del", "test", true); + TEST( R"del(\)del", "testa", false); + TEST(R"del(\)del", "test", true); +} diff --git a/benchmark/jeger_racer.cpp b/benchmark/jeger_racer.cpp new file mode 100644 index 0000000..5584927 --- /dev/null +++ b/benchmark/jeger_racer.cpp @@ -0,0 +1,83 @@ +#include + +static +void TEST(const char * const what, + const char * const on, + const bool expect){ + + regex_t * r = regex_compile(what); + bool result = regex_search(r, on); + regex_free(r); + +#if DEBUG + assert(expect == result); +#endif +} + +signed main(){ + TEST( R"del(abc)del", "abc", true); + TEST(R"del(efg1)del", "efg1", true); + TEST( R"del(nig)del", "ger", false); + TEST( R"del(ss)del", "sss", true); + TEST( R"del(sss)del", "ss", false); + + TEST( R"del(ab+c)del", "abc", true); + TEST(R"del(ef+g1)del", "effffg1", true); + TEST(R"del(efg1+)del", "efg", false); + TEST(R"del(efg1+)del", "efg1", true); + TEST(R"del(efg1+)del", "efg11", true); + + TEST( R"del(a+a)del", "aaa", true); + TEST( R"del(a+a)del", "aa", true); + TEST( R"del(a+a)del", "a", false); + TEST( R"del(a+a)del", "aaa", true); + TEST(R"del(a+\+)del", "aaa", false); + + TEST( R"del(ab*c)del", "abc", true); + TEST(R"del(ef*g1)del", "effffg1", true); + TEST(R"del(efg1*)del", "efg", true); + TEST(R"del(efg1*)del", "efg1", true); + TEST(R"del(efg1*)del", "efg11", true); + + TEST( R"del(ne.)del", "net", true); + TEST( R"del(ne.)del", "ne", false); + TEST(R"del(ne.+)del", "neoo", true); + TEST(R"del(ne.*)del", "neoo", true); + TEST(R"del(ne.*)del", "ne", true); + + TEST( R"del(ne.o)del", "neto", true); + TEST(R"del(ne.+o)del", "nettto", true); + TEST(R"del(ne.+o)del", "neo", false); + TEST(R"del(ne.+o)del", "neoo", true); + TEST(R"del(ne.*o)del", "neo", true); + + TEST(R"del(ne.)del", "ne\t", true); + TEST(R"del(ne\t)del", "ne", false); + TEST(R"del(ne\t)del", "ne\t", true); + TEST(R"del(ne\t)del", "net", false); + TEST(R"del(ne)del", "ne\t", true); + + TEST(R"del(\sa)del", " a", true); + TEST(R"del(\sa)del", " a ", true); + TEST(R"del(\wi)del", "hi", true); + TEST(R"del(\w+)del", "asd", true); + TEST(R"del(\w*)del", "", true); + + TEST( R"del([A-Za-z]+)del", "HelloWorld", true); + TEST(R"del([A-Za-z]+g)del", "HelloWorldg", true); + TEST(R"del([A-Za-z]+g)del", "g", false); + TEST(R"del([A-Za-z]*g)del", "g", true); + TEST(R"del([A-Za-z]+1)del", "1", false); + + TEST( R"del(^\^)del", "^^", true); + TEST( R"del(^\^)del", " ^", false); + TEST(R"del(^ \^)del", " ^", true); + TEST( R"del(^a*)del", "asd", true); + TEST( R"del(^)del", "", true); + + TEST( R"del(\)del", "test", true); + TEST( R"del(\)del", "testa", false); + TEST(R"del(\)del", "test", true); +}