From 9c97928751f958a1424ff95e98dd26c1859cafe4 Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Sun, 12 Jun 2022 01:24:55 +0200 Subject: [PATCH] Add benchmarks --- tests/shared/src/SerializerTests.cpp | 73 ++++++++++++++++++++++++++++ tests/shared/src/SerializerTests.h | 3 ++ 2 files changed, 76 insertions(+) diff --git a/tests/shared/src/SerializerTests.cpp b/tests/shared/src/SerializerTests.cpp index bc50554d96..a1b3a37544 100644 --- a/tests/shared/src/SerializerTests.cpp +++ b/tests/shared/src/SerializerTests.cpp @@ -111,6 +111,79 @@ void SerializerTests::testReadPastEnd() { QCOMPARE(s.pos(), 0); } +void SerializerTests::benchmarkEncodingDynamicAlloc() { + QBENCHMARK { + SerDes s; + glm::vec3 v3_a{1.f, 3.1415f, 2.71828f}; + glm::vec3 v3_b; + glm::vec4 v4_a{3.1415f, 2.71828f, 1.4142f, 1.6180f}; + glm::vec4 v4_b; + glm::ivec2 iv2_a{10, 24}; + glm::ivec2 iv2_b; + + s << (qint8)1; + s << (qint16)0xaabb; + s << (qint32)0xccddeeff; + s << v3_a; + s << v4_a; + s << iv2_a; + } +} + +void SerializerTests::benchmarkEncodingStaticAlloc() { + char buf[1024]; + + QBENCHMARK { + SerDes s(buf, sizeof(buf)); + glm::vec3 v3_a{1.f, 3.1415f, 2.71828f}; + glm::vec3 v3_b; + glm::vec4 v4_a{3.1415f, 2.71828f, 1.4142f, 1.6180f}; + glm::vec4 v4_b; + glm::ivec2 iv2_a{10, 24}; + glm::ivec2 iv2_b; + + s << (qint8)1; + s << (qint16)0xaabb; + s << (qint32)0xccddeeff; + s << v3_a; + s << v4_a; + s << iv2_a; + } +} + + +void SerializerTests::benchmarkDecoding() { + SerDes s; + qint8 q8 = 1; + qint16 q16 = 0xaabb; + qint32 q32 = 0xccddeeff; + + glm::vec3 v3_a{1.f, 3.1415f, 2.71828f}; + glm::vec3 v3_b; + glm::vec4 v4_a{3.1415f, 2.71828f, 1.4142f, 1.6180f}; + glm::vec4 v4_b; + glm::ivec2 iv2_a{10, 24}; + glm::ivec2 iv2_b; + + s << q8; + s << q16; + s << q32; + s << v3_a; + s << v4_a; + s << iv2_a; + + + QBENCHMARK { + s.rewind(); + s >> q8; + s >> q16; + s >> q32; + s >> v3_a; + s >> v4_a; + s >> iv2_a; + } +} + void SerializerTests::cleanupTestCase() { } diff --git a/tests/shared/src/SerializerTests.h b/tests/shared/src/SerializerTests.h index 1320d99c57..3a3a3217d2 100644 --- a/tests/shared/src/SerializerTests.h +++ b/tests/shared/src/SerializerTests.h @@ -21,6 +21,9 @@ private slots: void testAdd(); void testAddAndRead(); void testReadPastEnd(); + void benchmarkEncodingDynamicAlloc(); + void benchmarkEncodingStaticAlloc(); + void benchmarkDecoding(); void cleanupTestCase(); private: