From c3559b24eba76052deb9d4ce79e4704815d902a5 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 10 Feb 2020 20:58:39 +0200 Subject: staging: rewrite AdblockPlus parser yet again --- test/matcherbenchmark/matcherbenchmark.cpp | 85 ++++++++++++++++++++++++++++++ test/matcherbenchmark/matcherbenchmark.h | 19 +++++++ test/matcherbenchmark/meson.build | 5 ++ 3 files changed, 109 insertions(+) create mode 100644 test/matcherbenchmark/matcherbenchmark.cpp create mode 100644 test/matcherbenchmark/matcherbenchmark.h create mode 100644 test/matcherbenchmark/meson.build (limited to 'test/matcherbenchmark') diff --git a/test/matcherbenchmark/matcherbenchmark.cpp b/test/matcherbenchmark/matcherbenchmark.cpp new file mode 100644 index 0000000..1fd87cf --- /dev/null +++ b/test/matcherbenchmark/matcherbenchmark.cpp @@ -0,0 +1,85 @@ +#include "matcherbenchmark.h" +#include +#include +#include +#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 + { + 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); +} + +QTEST_GUILESS_MAIN(MatcherBenchmark) diff --git a/test/matcherbenchmark/matcherbenchmark.h b/test/matcherbenchmark/matcherbenchmark.h new file mode 100644 index 0000000..70fd859 --- /dev/null +++ b/test/matcherbenchmark/matcherbenchmark.h @@ -0,0 +1,19 @@ +#ifndef MATCHER_BENCHMARK +#define MATCHER_BENCHMARK + +#include + +class MatcherBenchmark : public QObject +{ + Q_OBJECT + +private slots: + void qstringcontains(); + void qstringmatcher(); + void qregexp(); + void qregularexpressionmatch(); + void stdregex(); + void cregex(); +}; + +#endif diff --git a/test/matcherbenchmark/meson.build b/test/matcherbenchmark/meson.build new file mode 100644 index 0000000..bc8327b --- /dev/null +++ b/test/matcherbenchmark/meson.build @@ -0,0 +1,5 @@ +executable('matcherbenchmarks', + sources: [ 'matcherbenchmark.cpp', + mod_qt5.preprocess(moc_headers: 'matcherbenchmark.h')], + dependencies: [ dep_qt5 ] +) -- cgit v1.2.1