aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-31 15:30:25 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-31 15:30:25 +0100
commitd193660622aff5ee114d2e5428d00865c286e555 (patch)
treeafbb309824fb8686246831d09f2427e562b3358f /test
parentFix various build warnings (diff)
downloadsmolbote-d193660622aff5ee114d2e5428d00865c286e555.tar.xz
Add more regex benchmarks
Diffstat (limited to 'test')
-rw-r--r--test/matcherbenchmark/matcherbenchmark.cpp42
-rw-r--r--test/matcherbenchmark/matcherbenchmark.h3
-rw-r--r--test/meson.build2
3 files changed, 45 insertions, 2 deletions
diff --git a/test/matcherbenchmark/matcherbenchmark.cpp b/test/matcherbenchmark/matcherbenchmark.cpp
index cb4feb1..84406d5 100644
--- a/test/matcherbenchmark/matcherbenchmark.cpp
+++ b/test/matcherbenchmark/matcherbenchmark.cpp
@@ -1,8 +1,12 @@
#include "matcherbenchmark.h"
+#include <string>
+#include <regex>
+#include <regex.h>
#include <QtTest/QTest>
#include <QRegExp>
#include <QRegularExpression>
#include <QStringMatcher>
+#include <boost/regex.hpp>
void MatcherBenchmark::qstringcontains()
{
@@ -44,7 +48,43 @@ void MatcherBenchmark::qregularexpressionmatch()
QCOMPARE(pattern.match(request).hasMatch(), true);
QBENCHMARK {
- QCOMPARE(pattern.match(request).hasMatch(), true);
+ pattern.match(request).hasMatch();
+ }
+}
+
+void MatcherBenchmark::stdregex()
+{
+ const std::regex pattern("spamdomain");
+ const std::string request("subdomain.spamdomain.com");
+
+ QCOMPARE(std::regex_search(request, pattern), true);
+ QBENCHMARK {
+ std::regex_search(request, pattern);
+ }
+}
+
+void MatcherBenchmark::cregex()
+{
+ regex_t pattern;
+ QCOMPARE(regcomp(&pattern, "spamdomain", 0), 0);
+ const std::string request("subdomain.spamdomain.com");
+
+ QCOMPARE(regexec(&pattern, request.c_str(), 0, NULL, 0), false);
+ QBENCHMARK {
+ regexec(&pattern, request.c_str(), 0, NULL, 0);
+ }
+
+ regfree(&pattern);
+}
+
+void MatcherBenchmark::boostregex()
+{
+ const boost::regex pattern("spamdomain");
+ const std::string request("subdomain.spamdomain.com");
+
+ QCOMPARE(boost::regex_search(request, pattern), true);
+ QBENCHMARK {
+ boost::regex_search(request, pattern);
}
}
diff --git a/test/matcherbenchmark/matcherbenchmark.h b/test/matcherbenchmark/matcherbenchmark.h
index cdc77f6..deb4495 100644
--- a/test/matcherbenchmark/matcherbenchmark.h
+++ b/test/matcherbenchmark/matcherbenchmark.h
@@ -12,6 +12,9 @@ private slots:
void qstringmatcher();
void qregexp();
void qregularexpressionmatch();
+ void stdregex();
+ void cregex();
+ void boostregex();
};
#endif
diff --git a/test/meson.build b/test/meson.build
index 3849f07..9be99c9 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -14,7 +14,7 @@ test('urlfilter-hostlist', hostlist)
# matching algorithms benchmark
matcherbenchmark = executable('MatcherBenchmark',
- dependencies: dep_qt5,
+ dependencies: [dep_qt5, dependency('boost', modules: 'regex')],
sources: ['matcherbenchmark/matcherbenchmark.cpp', qt5.preprocess(moc_headers: 'matcherbenchmark/matcherbenchmark.h', dependencies: dep_qt5)]
)