[Qt-interest] QString ot QUuid for QHash and QMap keys?

Andre Somers andre at familiesomers.nl
Fri Oct 21 20:41:23 CEST 2011


Op 21-10-2011 20:21, Jason H schreef:
> Yeah, I can find the quickest, but I was hoping for some insight :-)
Take a look at the implementation of the qHash function for the types.
I would think that it would be faster to compute a qHash for a QUuid 
than for a QString, as a QUuid is just a 16 byte integer value, while a 
QString can be any length, but for a QUuid it will be 36 2 byte 
characters. My guess is, that the fist will be faster to calculate than 
the second :-)

André


>
> *From:* Andre Somers <andre at familiesomers.nl>
> *To:* qt-interest at qt.nokia.com
> *Sent:* Friday, October 21, 2011 1:13 PM
> *Subject:* Re: [Qt-interest] QString ot QUuid for QHash and QMap keys?
>
> Op 21-10-2011 19:08, Jason H schreef:
>> I am wondering which if the following results in fastest lookups. 
>> I've got about 500-100o items in the collection, and I will 
>> constantly be doing lookups as the system gets the UUID for an object 
>> then proceeds to manipulate that object potentially several times a 
>> second, for each object.
>> QMap<QUuid, QObject*>
>> QHash<QUuid, QObject*>
>> QMap<QString, QObject*>
>> QHash<QString, QObject*>
>> Where the string keys are a QUuid::toString().mid(1,36) (trims the 
>> curley braces).
>> Also, why isn't there a toString() version that will just give me a 
>> string without the braces? I keep making Uuids, converting them to 
>> strings and cutting the braces off.
>> Thanks.
> The QHash versions are going to be faster than the QMap ones, but I am 
> not sure which of the hashes will be faster. I guess the QUuid one, 
> but that would be easy enough to benchmark, right?
>
> André
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com <mailto:Qt-interest at qt.nokia.com>
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20111021/299971af/attachment.html 


More information about the Qt-interest-old mailing list