-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.0
-
None
-
None
-
a891f20bc370c24777e22be40499e695f97738f9
Running the command QUuid::createUuid() on UNIX now takes 100 times longer than before 4.7.
While it takes 0.0011ms to perform the operation on Qt 4.6, it takes 2.02ms in Qt 4.7. This is because in 4.7 we check to see if /dev/urandom exists on Unix systems, and if it does we use this to generate a UUID with cryptographic quality, otherwise we fall back and use qrand() as before which is not cryptographic quality and not guaranteed to be unique (but much faster). If you want to patch QUuid to be use the old method, then comment out the following lines in
src/corelib/plugin/quuid.cpp:590
#ifdef Q_OS_UNIX
QFile devUrandom;
devUrandom.setFileName(QLatin1String("/dev/urandom"));
if (devUrandom.open(QIODevice::ReadOnly))
#include <QUuid>
#include <QDataStream>
#include <QBuffer>
#include <QtTest/QTest>
class UuIdBenchmark: public QObject
{
Q_OBJECT
public:
UuIdBenchmark()
{}
private:
QDataStream stream;
QBuffer buffer;
private slots:
void initTestCase()
void uuidBenchmark()
{
QBENCHMARK
}
};
QTEST_MAIN(UuIdBenchmark)
#include "main.moc"
This is not to say that this is not a more correct way of handling the proper creation of Uuid's, but such a large performance regression as a cost is unacceptable.
An effort should be made to make the performance of this call better for those who need to generate Uuid's frequently. This could for example be done by reading more than one UUID at the same time (caching) or keep /dev/random open for some time to reduce QFile overhead.