aboutsummaryrefslogtreecommitdiff
path: root/test/matcherbenchmark/matcherbenchmark.cpp
blob: 1fd87cff1e165897ec92b6e7dcf29e8e52ffbfc2 (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
#include "matcherbenchmark.h"
#include <QRegExp>
#include <QRegularExpression>
#include <QStringMatcher>
#include <QtTest/QTest>
#include <regex.h>
#include <regex>
#include <string>

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)