From 887ecc1aaa25f1068e666e009a08a8d28f3eed75 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 10 Apr 2015 16:09:35 +0200 Subject: [PATCH] Adding test to measure voxel access times when sampling the volume randomly. --- tests/testvolume.cpp | 39 +++++++++++++++++++++++++++++++++++++++ tests/testvolume.h | 3 +++ 2 files changed, 42 insertions(+) diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index 2215f933..6910abf0 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -219,6 +219,32 @@ int32_t testSamplersWithWrappingBackwards(VolumeType* volume, Region region) return result; } +template +int32_t testDirectRandomAccess(const VolumeType* volume) +{ + std::mt19937 rng; + int32_t result = 0; + + for (uint32_t ct = 0; ct < 10000; ct++) + { + uint32_t rand = rng(); + + // Four random number between 0-255 + uint32_t part0 = static_cast(rand & 0xFF); + int32_t part1 = static_cast((rand >> 8) & 0xFF); + int32_t part2 = static_cast((rand >> 16) & 0xFF); + int32_t part3 = static_cast((rand >> 24) & 0xFF); + + result = cantorTupleFunction(result, volume->getVoxel(part0, part1, part2)); + result = cantorTupleFunction(result, volume->getVoxel(part1, part2, part3)); + result = cantorTupleFunction(result, volume->getVoxel(part2, part3, part0)); + result = cantorTupleFunction(result, volume->getVoxel(part3, part0, part1)); + + } + + return result; +} + TestVolume::TestVolume() { m_regVolume = Region(-57, -31, 12, 64, 96, 131); // Deliberatly awkward size @@ -452,6 +478,19 @@ void TestVolume::testPagedVolumeSamplersWithExternalBackwards() QCOMPARE(result, static_cast(-993539594)); } +/* + * Random access tests + */ +void TestVolume::testPagedVolumeDirectRandomAccess() +{ + int32_t result = 0; + QBENCHMARK + { + result = testDirectRandomAccess(m_pPagedVolume); + } + QCOMPARE(result, static_cast(805464457)); +} + int32_t TestVolume::testPagedVolumeChunkAccess(uint16_t localityMask) { std::mt19937 rng; diff --git a/tests/testvolume.h b/tests/testvolume.h index 617222df..e189cbc9 100644 --- a/tests/testvolume.h +++ b/tests/testvolume.h @@ -57,6 +57,8 @@ private slots: void testPagedVolumeDirectAccessWithExternalBackwards(); void testPagedVolumeSamplersWithExternalBackwards(); + void testPagedVolumeDirectRandomAccess(); + void testPagedVolumeChunkLocalAccess(); void testPagedVolumeChunkRandomAccess(); @@ -72,6 +74,7 @@ private: PolyVox::RawVolume* m_pRawVolume; PolyVox::PagedVolume* m_pPagedVolume; + PolyVox::PagedVolume* m_pPagedVolumeHighMem; PolyVox::PagedVolume::Chunk* m_pPagedVolumeChunk; };