Adding QJsonObject to QJsonDocument takes a lot of time
-
QJsonObject rootObj; rootObj["a1"]=a1obj; rootObj["a2"]=a2obj; rootObj["a3"]=a3obj; rootObj["a4"]=a4obj; rootObj["a5"]=a5obj; QJsonDocument newDocument(rootObj);This part of my code creates a lot of delay in the application. It takes approximately 100 ms. How do I speed this up?
-
Hi,
What are all these objects ?
How did you measure the time ?
Are you using a debug build ?
On which OS are you seeing that ?
Which version of Qt are you using ? -
Hi,
What are all these objects ?
How did you measure the time ?
Are you using a debug build ?
On which OS are you seeing that ?
Which version of Qt are you using ?@SGaist
All objects are QString.
I calculate by putting qtime in the upper and lower parts. Even if I don't do this, it creates a slowness in the interface anyway.
No i am using release build.
Windows 10.
6.6.0.
Thank you. -
@SGaist
All objects are QString.
I calculate by putting qtime in the upper and lower parts. Even if I don't do this, it creates a slowness in the interface anyway.
No i am using release build.
Windows 10.
6.6.0.
Thank you.Hi @MrHandSOme,
I calculate by putting qtime in the upper and lower parts.
QTimehas some overhead (probably very little, but still...). For interest, try this:const quint64 start = QDateTime::currentMSecsSinceEpoch(); QJsonObject rootObj; qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "rootObj"; rootObj[QStringLiteral("a1")]=QStringLiteral("a1obj"); qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "a1obj"; rootObj[QStringLiteral("a2")]=QStringLiteral("a2obj"); qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "a2obj"; rootObj[QStringLiteral("a3")]=QStringLiteral("a3obj"); qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "a3obj"; rootObj[QStringLiteral("a4")]=QStringLiteral("a4obj"); qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "a4obj"; rootObj[QStringLiteral("a5")]=QStringLiteral("a5obj"); qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "a5obj"; QJsonDocument newDocument(rootObj); qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "newDocument";For me (on Linux though, I don't have Windows handy just at the moment), it shows all of that code executing within a single millisecond, as expected. My output:
0 rootObj 1 a1obj 1 a2obj 1 a3obj 1 a4obj 1 a5obj 1 newDocumentIf that code is slow for you, show us the output. If it's not slow, then try replacing the various
QStringLiteral()'s with your versions one at a time and see if that reveals anything.Cheers.