From 197175c8b9e11fce379e77bdba6441c74097bd58 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 21 Oct 2018 14:25:52 +0200 Subject: Add MatcherBenchmark --- test/matcherbenchmark/matcherbenchmark.cpp | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/matcherbenchmark/matcherbenchmark.cpp (limited to 'test/matcherbenchmark/matcherbenchmark.cpp') 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 +#include +#include +#include + +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) -- cgit v1.2.1