D26366: [Kuit] Port QRegExp to QRegularExpression, third pass

Ahmad Samir noreply at phabricator.kde.org
Mon Jan 6 08:18:49 GMT 2020


ahmadsamir added a comment.


  I hacked up some (rather crude, to say the least) benchmarking:
  
    void KLocalizedStringTest::benchmarkRegexSimple()
    {
        QString roleName, cueName, formatName;
        QString context = QStringLiteral("@info:tooltip/plaintext");
    
        QBENCHMARK {
            if (context.startsWith(QLatin1Char('@'))) { // found UI marker
                static QRegularExpression wsRx(QStringLiteral("\\s"));
                context = context.mid(1, wsRx.match(context).capturedStart(0) - 1);
    
                // Possible format.
                int pfmt = context.indexOf(QLatin1Char('/'));
                if (pfmt >= 0) {
                    formatName = context.mid(pfmt + 1);
                    context.truncate(pfmt);
                }
    
                // Possible subcue.
                int pcue = context.indexOf(QLatin1Char(':'));
                if (pcue >= 0) {
                    cueName = context.mid(pcue + 1);
                    context.truncate(pcue);
                }
    
                // Role.
                roleName = context;
            }
        }
    }
    
    void KLocalizedStringTest::benchmarkRegex2()
    {
        QString roleName, cueName, formatName;
        QString context = QStringLiteral("@info:tooltip/plaintext");
    
        QBENCHMARK {
            static const QRegularExpression rolesRx(QStringLiteral("^@(\\w+):?(\\w*)/?(\\w*)"));
            const QRegularExpressionMatch match = rolesRx.match(context);
            if (match.hasMatch()) {
                roleName = match.captured(1);
                cueName = match.captured(2);
                formatName = match.captured(3);
            }
        }
    }
  
  and the results were:
  
    PASS   : KLocalizedStringTest::benchmarkRegexSimple()
    RESULT : KLocalizedStringTest::benchmarkRegexSimple():
         0.0000098 msecs per iteration (total: 83, iterations: 8388608)
    PASS   : KLocalizedStringTest::benchmarkRegex2()
    RESULT : KLocalizedStringTest::benchmarkRegex2():
         0.00054 msecs per iteration (total: 72, iterations: 131072)
  
  it doesn't look like a lot of difference to me; WDYT?

REPOSITORY
  R249 KI18n

REVISION DETAIL
  https://phabricator.kde.org/D26366

To: ahmadsamir, #frameworks, ilic, dfaure, mlaurent, aacid
Cc: kde-frameworks-devel, LeGast00n, GB_2, michaelh, ngraham, bruns
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20200106/09254550/attachment-0001.html>


More information about the Kde-frameworks-devel mailing list