[Development] Json support for QtCore
lars.knoll at nokia.com
lars.knoll at nokia.com
Sun Dec 11 15:47:21 CET 2011
On 12/11/11 1:31 AM, "ext Robin Burchell" <robin+qt at viroteck.net> wrote:
>hi,
>
>On Sat, Dec 10, 2011 at 10:32 PM, <lars.knoll at nokia.com> wrote:
>> I've benchmarked parsing speed and compared to the qjson
>> (http://qjson.sourceforge.net/). It's around 7 times faster for the
>> test.json file included in the project (the test case used in qjson as
>> well).
>
>I'd be interested to see how your parser fares compared to girish's
>work (existing benchmark results, somewhat outdated probably, found at
>http://git.forwardbias.in/?p=qjsonparser.git;a=commit;h=180f3a1ea85adbea4d
>77e50ff3be3e75af918252)
>- those results at least look a lot better than 7 times faster, but
>they are also probably different test data.
I was actually posting results for qjsonparser yesterday (sorry for
wrongly stating it was qjson).
I now redid the benchmarks comparing qjson (as provided by my Ubuntu
install, linked against Qt 4.7), qjsonparser (latest HEAD, linked against
Qt 5) and my qtbinaryjson (linked against Qt5 as well). Here are the
numbers:
qjson:
********* Start testing of tst_Json *********
Config: Using QTest library 4.7.2, Qt 4.7.2
PASS : tst_Json::initTestCase()
RESULT : tst_Json::testByteArray():
16 msecs per iteration (total: 65, iterations: 4)
PASS : tst_Json::testByteArray()
RESULT : tst_Json::testNumbers():
0.19 msecs per iteration (total: 98, iterations: 512)
PASS : tst_Json::testNumbers()
PASS : tst_Json::cleanupTestCase()
Totals: 4 passed, 0 failed, 0 skipped
********* Finished testing of tst_Json *********
qjsonparser:
********* Start testing of tst_Json *********
Config: Using QTest library 5.0.0, Qt 5.0.0
PASS : tst_Json::initTestCase()
RESULT : tst_Json::testByteArray():
1.2 msecs per iteration (total: 83, iterations: 64)
PASS : tst_Json::testByteArray()
RESULT : tst_Json::testString():
1.2 msecs per iteration (total: 80, iterations: 64)
PASS : tst_Json::testString()
RESULT : tst_Json::testNumbers():
0.013 msecs per iteration (total: 57, iterations: 4096)
PASS : tst_Json::testNumbers()
PASS : tst_Json::cleanupTestCase()
Totals: 5 passed, 0 failed, 0 skipped
********* Finished testing of tst_Json *********
qtbinaryjson:
********* Start testing of BenchmarkQtBinaryJson *********
Config: Using QTest library 5.0.0, Qt 5.0.0
PASS : BenchmarkQtBinaryJson::initTestCase()
RESULT : BenchmarkQtBinaryJson::parseNumbers():
0.0054 msecs per iteration (total: 89, iterations: 16384)
PASS : BenchmarkQtBinaryJson::parseNumbers()
RESULT : BenchmarkQtBinaryJson::parseJson():
0.32 msecs per iteration (total: 82, iterations: 256)
PASS : BenchmarkQtBinaryJson::parseJson()
RESULT : BenchmarkQtBinaryJson::parseJsonToVariant():
0.90 msecs per iteration (total: 58, iterations: 64)
PASS : BenchmarkQtBinaryJson::parseJsonToVariant()
PASS : BenchmarkQtBinaryJson::cleanupTestCase()
Totals: 5 passed, 0 failed, 0 skipped
********* Finished testing of BenchmarkQtBinaryJson *********
parseNumbers is parsing the numbers.json file from qjsonparser, the other
tests parse the test.json file from the same source. The file is fully
being loaded into a QByteArray (or QString for one of the qjsonparser
tests), and only the parsing afterwards is being benchmarked.
qjson is clearly slowest. qtbinaryjson is 4 times faster that qjsonparser
and still beats it even when converting the parsed result to a QVariant.
>
>But, parser aside: in general terms, I do think I agree that
>converting to/from QVariant as an "API" isn' all that nice, so your
>approach is a nice alternative.
Thanks.
>
>I do think I'd like to see QDataStream operators on QJsonDocument,
>btw. sending json documents in binary form to/from files or sockets
>would be useful.
That should be very easy to add. Patches welcome :)
Cheers,
Lars
More information about the Development
mailing list