summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKurt Korbatits <kurt.korbatits@nokia.com>2012-03-19 14:54:16 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-22 00:00:28 +0100
commitbcba6ed25244b36a7975a7c1bc429732d54818d1 (patch)
tree4e445ee199d250ed2af123a5419535cf332a26a4
parentdf6a08951af9005ef86d3eb43ef2816a74837a9f (diff)
Added extra tests to json benchmark
- Added toByteArray() and fromByteArray() benchmark tests. Performance tests to measure QVariantMap to bytearray and bytearray to QVariantMap. Use case: Interprocess communications via local socket Change-Id: If5e94ff870890b2ebb665f3cc38f5c33b34547f4 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
-rw-r--r--tests/benchmarks/corelib/json/tst_bench_qtbinaryjson.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/json/tst_bench_qtbinaryjson.cpp b/tests/benchmarks/corelib/json/tst_bench_qtbinaryjson.cpp
index 2253d00778..e4e10ba2ba 100644
--- a/tests/benchmarks/corelib/json/tst_bench_qtbinaryjson.cpp
+++ b/tests/benchmarks/corelib/json/tst_bench_qtbinaryjson.cpp
@@ -58,6 +58,8 @@ private Q_SLOTS:
void parseNumbers();
void parseJson();
void parseJsonToVariant();
+ void toByteArray();
+ void fromByteArray();
};
BenchmarkQtBinaryJson::BenchmarkQtBinaryJson(QObject *parent) : QObject(parent)
@@ -127,6 +129,36 @@ void BenchmarkQtBinaryJson::parseJsonToVariant()
}
}
+void BenchmarkQtBinaryJson::toByteArray()
+{
+ // Example: send information over a datastream to another process
+ // Measure performance of creating and processing data into bytearray
+ QBENCHMARK {
+ QVariantMap message;
+ message.insert("command", 1);
+ message.insert("key", "some information");
+ message.insert("env", "some environment variables");
+ QByteArray msg = QJsonDocument(QJsonObject::fromVariantMap(message)).toBinaryData();
+ }
+}
+
+void BenchmarkQtBinaryJson::fromByteArray()
+{
+ // Example: receive information over a datastream from another process
+ // Measure performance of converting content back to QVariantMap
+ // We need to recreate the bytearray but here we only want to measure the latter
+ QVariantMap message;
+ message.insert("command", 1);
+ message.insert("key", "some information");
+ message.insert("env", "some environment variables");
+ QByteArray msg = QJsonDocument(QJsonObject::fromVariantMap(message)).toBinaryData();
+
+ QBENCHMARK {
+ QVariantMap message;
+ message = QJsonDocument::fromBinaryData(msg, QJsonDocument::Validate).object().toVariantMap();
+ }
+}
+
QTEST_MAIN(BenchmarkQtBinaryJson)
#include "tst_bench_qtbinaryjson.moc"