Expensive QString = ""

André Wöbbeking kde-optimize@mail.kde.org
Wed, 12 Mar 2003 01:02:25 +0100


Hi,

just FYI. The code

    QString s;

    QTime t;
    t.start();

    for (int i(0); i < 10000000; ++i)
        s = "";

    qDebug("= \"\"            %7d ms", t.restart());

    for (int i(0); i < 10000000; ++i)
        s = QString::null;

    qDebug("= QString::null %7d ms", t.elapsed());

gives me (Athlon 1133 MHz) the following output:

= ""              11716 ms
= QString::null     351 ms

I don't know, if QString = "" appears frequently in time critical code (KHtml, 
KDE start up, KConfig, ...), but if you really need an empty QString the 
better solution would be to use a static const QString like QString::null.


Cheers
André