Den 30. sep. 2011 14:11, skrev ext Olivier Goffart:
> 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 :-)

Nope :)


>> 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?

Good point :)

> 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.

So appending QLatin1String can be made faster?! That's horrible news, we 
want QStringLiteral to beat it massively, remember :P


>> 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.

Lots of good ideas here, please update the benchmark and pass it around :D

>
>> 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.

Yeah. On a related note, I replaced as many QLatin1Strings by 
QStringLiteral in QtCore as possible, and the library size increase was 
1% (40K) on ia32.

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

Reply via email to