From a9f1a29868156b95bd33521b5de57c981ba99888 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 5 Sep 2014 16:06:40 +0200 Subject: [PATCH] Adding Vector performance test. --- tests/testvector.cpp | 22 ++++++++++++++++++++++ tests/testvector.h | 1 + 2 files changed, 23 insertions(+) diff --git a/tests/testvector.cpp b/tests/testvector.cpp index 78d24383..08649f28 100644 --- a/tests/testvector.cpp +++ b/tests/testvector.cpp @@ -29,6 +29,12 @@ freely, subject to the following restrictions: using namespace PolyVox; +Vector3DFloat incrementVector(Vector3DFloat input) +{ + Vector3DFloat result = input += 1.0f; + return result; +} + void TestVector::testLength() { Vector3DInt8 vec(3, 4, 5); @@ -51,4 +57,20 @@ void TestVector::testEquality() QCOMPARE(vecxy != vecz, true); } +void TestVector::testPerformance() +{ + Vector3DFloat vec(1.0, 1.0, 1.0); + + QBENCHMARK + { + for(uint32_t ct = 0; ct < 10000000; ct++) + { + vec = incrementVector(vec); + } + } + + // Use the result so the calls don't get optimized away. + QCOMPARE(vec.lengthSquared() > 0.0f, true); +} + QTEST_MAIN(TestVector) diff --git a/tests/testvector.h b/tests/testvector.h index baad1e3d..53ed5718 100644 --- a/tests/testvector.h +++ b/tests/testvector.h @@ -34,6 +34,7 @@ class TestVector: public QObject void testLength(); void testDotProduct(); void testEquality(); + void testPerformance(); }; #endif