aboutsummaryrefslogtreecommitdiff
path: root/test/matcherbenchmark/matcherbenchmark.cpp
blob: 84406d5f5835f1fbf5cd29c93e830c20689ad50f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "matcherbenchmark.h"
#include <string>
#include <regex>
#include <regex.h>
#include <QtTest/QTest>
#include <QRegExp>
#include <QRegularExpression>
#include <QStringMatcher>
#include <boost/regex.hpp>

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);
}

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);
    }
}

QTEST_GUILESS_MAIN(MatcherBenchmark)