diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-21 14:25:52 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-21 14:25:52 +0200 |
commit | 197175c8b9e11fce379e77bdba6441c74097bd58 (patch) | |
tree | d0dfa5bcc6514ad0ac52c8d8b61f638a646a08b0 /test/matcherbenchmark | |
parent | urlfilter: base AdBlockRule off FilterLeaf (diff) | |
download | smolbote-197175c8b9e11fce379e77bdba6441c74097bd58.tar.xz |
Add MatcherBenchmark
Diffstat (limited to 'test/matcherbenchmark')
-rw-r--r-- | test/matcherbenchmark/matcherbenchmark.cpp | 51 | ||||
-rw-r--r-- | test/matcherbenchmark/matcherbenchmark.h | 17 |
2 files changed, 68 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) diff --git a/test/matcherbenchmark/matcherbenchmark.h b/test/matcherbenchmark/matcherbenchmark.h new file mode 100644 index 0000000..cdc77f6 --- /dev/null +++ b/test/matcherbenchmark/matcherbenchmark.h @@ -0,0 +1,17 @@ +#ifndef MATCHER_BENCHMARK +#define MATCHER_BENCHMARK + +#include <QObject> + +class MatcherBenchmark : public QObject +{ + Q_OBJECT + +private slots: + void qstringcontains(); + void qstringmatcher(); + void qregexp(); + void qregularexpressionmatch(); +}; + +#endif |