aboutsummaryrefslogtreecommitdiff
path: root/test/matcherbenchmark
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/matcherbenchmark
parentFix various build warnings (diff)
downloadsmolbote-d193660622aff5ee114d2e5428d00865c286e555.tar.xz
Add more regex benchmarks
Diffstat (limited to 'test/matcherbenchmark')
-rw-r--r--test/matcherbenchmark/matcherbenchmark.cpp42
-rw-r--r--test/matcherbenchmark/matcherbenchmark.h3
2 files changed, 44 insertions, 1 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