aboutsummaryrefslogtreecommitdiff
path: root/test/matcherbenchmark/matcherbenchmark.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/matcherbenchmark/matcherbenchmark.cpp')
-rw-r--r--test/matcherbenchmark/matcherbenchmark.cpp42
1 files changed, 41 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);
}
}