From d193660622aff5ee114d2e5428d00865c286e555 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 31 Oct 2018 15:30:25 +0100 Subject: Add more regex benchmarks --- test/matcherbenchmark/matcherbenchmark.cpp | 42 +++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'test/matcherbenchmark/matcherbenchmark.cpp') 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 +#include +#include #include #include #include #include +#include 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); } } -- cgit v1.2.1