summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2011-12-09 14:37:13 +0100
committerHicks James <jamey.hicks@nokia.com>2011-12-09 16:02:58 +0100
commit4a90a9b64ca6469400deb1349e0b2e118de705ef (patch)
tree7c494ab81220dfe09e60056b6bd5272cae399283
parenta6f10f0df5945653ef3f723f19664fa52e0490ec (diff)
Add a parsing benchmark using test.json
The results when building in release mode show that the parser is around 7 times faster than the one in qjson. Change-Id: I86b061091a8f32444b75891b0b4402aa8c66dc65 Reviewed-by: Hicks James <jamey.hicks@nokia.com>
-rw-r--r--tests/benchmarks/benchmarks.pro4
-rw-r--r--tests/benchmarks/tst_bench_qtbinaryjson.cpp18
2 files changed, 21 insertions, 1 deletions
diff --git a/tests/benchmarks/benchmarks.pro b/tests/benchmarks/benchmarks.pro
index 3e4ae6d..62cd2c4 100644
--- a/tests/benchmarks/benchmarks.pro
+++ b/tests/benchmarks/benchmarks.pro
@@ -1,3 +1,7 @@
TARGET = tst_bench_qtbinaryjson
QT = core testlib
SOURCES += tst_bench_qtbinaryjson.cpp
+LIBS += -L../../lib -lqtjson
+INCLUDEPATH += ../../src
+
+QMAKE_LFLAGS += "-Wl,-rpath,$$PWD/../../lib"
diff --git a/tests/benchmarks/tst_bench_qtbinaryjson.cpp b/tests/benchmarks/tst_bench_qtbinaryjson.cpp
index 2f1c0de..228e479 100644
--- a/tests/benchmarks/tst_bench_qtbinaryjson.cpp
+++ b/tests/benchmarks/tst_bench_qtbinaryjson.cpp
@@ -38,7 +38,9 @@
****************************************************************************/
#include <QtTest>
-
+#include <qjsondocument.h>
+#include <qjsonobject.h>
+using namespace QtJson;
class BenchmarkQtBinaryJson: public QObject
{
@@ -51,6 +53,8 @@ private Q_SLOTS:
void cleanupTestCase();
void init();
void cleanup();
+
+ void parseJson();
};
BenchmarkQtBinaryJson::BenchmarkQtBinaryJson(QObject *parent) : QObject(parent)
@@ -78,6 +82,18 @@ void BenchmarkQtBinaryJson::cleanup()
}
+void BenchmarkQtBinaryJson::parseJson()
+{
+ QFile file(QLatin1String("../auto/test.json"));
+ file.open(QFile::ReadOnly);
+ QByteArray testJson = file.readAll();
+
+ QBENCHMARK {
+ JsonDocument doc = JsonDocument::fromJson(testJson);
+ JsonObject object = doc.object();
+ }
+}
+
QTEST_MAIN(BenchmarkQtBinaryJson)
#include "tst_bench_qtbinaryjson.moc"