Kent Hansen
2011-09-30 10:57:28 UTC
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]
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.
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.
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.
Regards,
Kent
[1] http://www.macieira.org/blog/2011/07/qstring-improved/
[2] http://pastebin.com/jmpNAAFG
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]
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.
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.
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.
Regards,
Kent
[1] http://www.macieira.org/blog/2011/07/qstring-improved/
[2] http://pastebin.com/jmpNAAFG