On Friday 30 September 2011 12:57:28 Kent Hansen wrote:
> Hi,
> You might have seen Thiago's blog about QStringLiteral [1], and his idea
> on replacing QLatin1String usage by QStringLiteral in Qt (where possible).
> 
> I like the idea, but wanted to do some benchmarking first to get an
> impression of the performance impact. [2]

You could have used template instead of macros :-)

> My results so far (on Linux 32-bit) indicate that QString::appends are
> way faster when switching to using QStringLiteral: 7x faster than
> QLatin1String for a 2-character literal and 14x for a ~50-character literal.

That is because you append to a null string.
Appending a QString to a null string is equivalent to the operator=  (that is, 
only setting a pointer)
could you change the benchmark to append to something?

Also, appending with QLatin1String currently do not do the sse2 fromLatin1, it 
would be trivial do so by extracting the fromLatin1 code to a helper helper  
function.

> Now, the not-so-good news: operator==(QString) is a bit (just a bit)
> slower than operator==(QLatin1String) for short strings.
> It seems that, for short strings, the overhead of calling qMemEquals()
> and performing its "housecleaning chores" outweigh the benefits of its
> fast comparison loop.

It would be nice to compare with different lenght AND different on the first 
char.
Or better, with actual data extracted form a qDebug in the operator== for a 
random application.


> In other words, if someone were to optimize QString::operator==(QString)
> to perform better for small strings, the total replacement would be a
> done deal.

Another thing that need to be taken in account is that QStringLiteral takes 
more memory in the binary. Hence, more cache misses.
This is difficult to show in a benchmark that runs over the same data all the 
time.

_______________________________________________
Qt5-feedback mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback

Reply via email to