mirror of https://github.com/qt/qtgrpc.git
Protobuf: Add basic deserialize benchmark
Change-Id: I382269cd59c4f96f3f8e1956b8a1a97836e5b057 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
parent
5f11f7fee6
commit
ed50bef7d1
|
@ -0,0 +1,4 @@
|
||||||
|
# Copyright (C) 2024 The Qt Company Ltd.
|
||||||
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
add_subdirectory(protobuf)
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Copyright (C) 2024 The Qt Company Ltd.
|
||||||
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
add_subdirectory(deserialize)
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Copyright (C) 2024 The Qt Company Ltd.
|
||||||
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
qt_internal_add_benchmark(tst_bench_deserialize_protobuf
|
||||||
|
SOURCES
|
||||||
|
tst_bench_deserialize_protobuf.cpp
|
||||||
|
INCLUDE_DIRECTORIES
|
||||||
|
.
|
||||||
|
LIBRARIES
|
||||||
|
Qt::Test
|
||||||
|
Qt::Protobuf
|
||||||
|
)
|
||||||
|
|
||||||
|
qt6_add_protobuf(tst_bench_deserialize_protobuf
|
||||||
|
PROTO_FILES
|
||||||
|
data/bench.proto
|
||||||
|
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated"
|
||||||
|
)
|
|
@ -0,0 +1,21 @@
|
||||||
|
// Copyright (C) 2024 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package qtbench;
|
||||||
|
|
||||||
|
message EmptyMessage {}
|
||||||
|
|
||||||
|
message SimpleBoolMessage {
|
||||||
|
bool testFieldBool = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SimpleBytesMessage {
|
||||||
|
bytes testFieldBytes = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RecursiveMessage {
|
||||||
|
int32 testFieldInt = 1;
|
||||||
|
RecursiveMessage testFieldRecursive = 2;
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
// Copyright (C) 2024 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||||
|
|
||||||
|
#include <QtTest/qtest.h>
|
||||||
|
|
||||||
|
#include <QtProtobuf/qprotobufserializer.h>
|
||||||
|
|
||||||
|
#include "bench.qpb.h"
|
||||||
|
|
||||||
|
class tst_ProtoDeserialize : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void deserialize_data();
|
||||||
|
void deserialize();
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<std::pair<QString, QByteArray>, 3> data = {
|
||||||
|
std::make_pair("qtbench.SimpleBoolMessage", QByteArray::fromHex("0801")),
|
||||||
|
std::make_pair("qtbench.SimpleBytesMessage", QByteArray::fromHex("0a0c48656c6c6f20776f726c6421")),
|
||||||
|
std::make_pair("qtbench.RecursiveMessage", QByteArray::fromHex("080112120802120e0803120a08041206080512020806")),
|
||||||
|
};
|
||||||
|
|
||||||
|
void tst_ProtoDeserialize::deserialize_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("name");
|
||||||
|
QTest::addColumn<QByteArray>("data");
|
||||||
|
|
||||||
|
for (auto &&[name, value] : data)
|
||||||
|
QTest::newRow(qPrintable(name)) << name << value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_ProtoDeserialize::deserialize()
|
||||||
|
{
|
||||||
|
QFETCH(QString, name);
|
||||||
|
QFETCH(QByteArray, data);
|
||||||
|
|
||||||
|
QProtobufSerializer serializer;
|
||||||
|
QBENCHMARK {
|
||||||
|
QProtobufMessagePointer res = QProtobufMessage::constructByName(name);
|
||||||
|
QVERIFY(res);
|
||||||
|
QVERIFY(res->deserialize(&serializer, data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_MAIN(tst_ProtoDeserialize)
|
||||||
|
|
||||||
|
#include "tst_bench_deserialize_protobuf.moc"
|
Loading…
Reference in New Issue