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.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/matcherbenchmark/matcherbenchmark.cpp b/test/matcherbenchmark/matcherbenchmark.cpp
new file mode 100644
index 0000000..cb4feb1
--- /dev/null
+++ b/test/matcherbenchmark/matcherbenchmark.cpp
@@ -0,0 +1,51 @@
+#include "matcherbenchmark.h"
+#include <QtTest/QTest>
+#include <QRegExp>
+#include <QRegularExpression>
+#include <QStringMatcher>
+
+void MatcherBenchmark::qstringcontains()
+{
+ const QString pattern("spamdomain");
+ const QString request("subdomain.spamdomain.com");
+
+ QCOMPARE(request.contains(pattern), true);
+ QBENCHMARK {
+ request.contains(pattern);
+ }
+}
+
+void MatcherBenchmark::qstringmatcher()
+{
+ const QStringMatcher pattern("spamdomain");
+ const QString request("subdomain.spamdomain.com");
+
+ QCOMPARE(pattern.indexIn(request) != -1, true);
+ QBENCHMARK {
+ pattern.indexIn(request);
+ }
+}
+
+void MatcherBenchmark::qregexp()
+{
+ const QRegExp pattern("spamdomain");
+ const QString request("subdomain.spamdomain.com");
+
+ QCOMPARE(pattern.indexIn(request) != -1, true);
+ QBENCHMARK {
+ pattern.indexIn(request);
+ }
+}
+
+void MatcherBenchmark::qregularexpressionmatch()
+{
+ const QRegularExpression pattern("spamdomain");
+ const QString request("subdomain.spamdomain.com");
+
+ QCOMPARE(pattern.match(request).hasMatch(), true);
+ QBENCHMARK {
+ QCOMPARE(pattern.match(request).hasMatch(), true);
+ }
+}
+
+QTEST_GUILESS_MAIN(MatcherBenchmark)