From 1d24b189ca7f875ee267ec82f4217f283aa65603 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 25 Mar 2015 17:12:11 +0100 Subject: [PATCH] Refactoed test code. --- tests/testvolume.cpp | 51 ++++++++++++++++++++++---------------------- tests/testvolume.h | 2 ++ 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index aa7658bb..37f38d0c 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -468,49 +468,50 @@ void TestVolume::testPagedVolumeSamplersWithExternalBackwards() QCOMPARE(result, static_cast(-993539594)); } -void TestVolume::testPagedVolumeChunkLocalAccess() +int32_t TestVolume::testPagedVolumeChunkAccess(uint32_t locality) { std::mt19937 rng; int32_t result = 0; uint16_t x = rng() % m_uChunkSideLength; uint16_t y = rng() % m_uChunkSideLength; uint16_t z = rng() % m_uChunkSideLength; + + for (uint32_t ct = 0; ct < 1000000; ct++) + { + uint16_t xOffset = rng() % locality; + uint16_t yOffset = rng() % locality; + uint16_t zOffset = rng() % locality; + x += xOffset; + y += yOffset; + z += zOffset; + x %= m_uChunkSideLength; + y %= m_uChunkSideLength; + z %= m_uChunkSideLength; + int32_t voxel = m_pPagedVolumeChunk->getVoxel(x, y, z); + result = cantorTupleFunction(result, voxel); + } + + return result; +} + +void TestVolume::testPagedVolumeChunkLocalAccess() +{ + int32_t result = 0; QBENCHMARK { - for (uint32_t ct = 0; ct < 1000000; ct++) - { - uint16_t xOffset = rng() % 3; - uint16_t yOffset = rng() % 3; - uint16_t zOffset = rng() % 3; - x += xOffset; - y += yOffset; - z += zOffset; - x %= m_uChunkSideLength; - y %= m_uChunkSideLength; - z %= m_uChunkSideLength; - int32_t voxel = m_pPagedVolumeChunk->getVoxel(x, y, z); - result = cantorTupleFunction(result, voxel); - } + result = testPagedVolumeChunkAccess(3); // Small value for good locality } QCOMPARE(result, static_cast(145244783)); } void TestVolume::testPagedVolumeChunkRandomAccess() { - std::mt19937 rng; int32_t result = 0; QBENCHMARK { - for (uint32_t ct = 0; ct < 1000000; ct++) - { - uint16_t x = rng() % m_uChunkSideLength; - uint16_t y = rng() % m_uChunkSideLength; - uint16_t z = rng() % m_uChunkSideLength; - int32_t voxel = m_pPagedVolumeChunk->getVoxel(x, y, z); - result = cantorTupleFunction(result, voxel); - } + result = testPagedVolumeChunkAccess(1000000); // Large value for poor locality (random access) } - QCOMPARE(result, static_cast(408757678)); + QCOMPARE(result, static_cast(-254578110)); } QTEST_MAIN(TestVolume) diff --git a/tests/testvolume.h b/tests/testvolume.h index e17534dd..a0f1e829 100644 --- a/tests/testvolume.h +++ b/tests/testvolume.h @@ -61,6 +61,8 @@ private slots: void testPagedVolumeChunkRandomAccess(); private: + int32_t testPagedVolumeChunkAccess(uint32_t locality); + static const uint16_t m_uChunkSideLength = 32; PolyVox::Region m_regVolume;