Adding test to measure voxel access times when sampling the volume randomly.

This commit is contained in:
David Williams 2015-04-10 16:09:35 +02:00
parent 27a59f34bc
commit 887ecc1aaa
2 changed files with 42 additions and 0 deletions

View File

@ -219,6 +219,32 @@ int32_t testSamplersWithWrappingBackwards(VolumeType* volume, Region region)
return result;
}
template <typename VolumeType>
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<int32_t>(rand & 0xFF);
int32_t part1 = static_cast<int32_t>((rand >> 8) & 0xFF);
int32_t part2 = static_cast<int32_t>((rand >> 16) & 0xFF);
int32_t part3 = static_cast<int32_t>((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<int32_t>(-993539594));
}
/*
* Random access tests
*/
void TestVolume::testPagedVolumeDirectRandomAccess()
{
int32_t result = 0;
QBENCHMARK
{
result = testDirectRandomAccess(m_pPagedVolume);
}
QCOMPARE(result, static_cast<int32_t>(805464457));
}
int32_t TestVolume::testPagedVolumeChunkAccess(uint16_t localityMask)
{
std::mt19937 rng;

View File

@ -57,6 +57,8 @@ private slots:
void testPagedVolumeDirectAccessWithExternalBackwards();
void testPagedVolumeSamplersWithExternalBackwards();
void testPagedVolumeDirectRandomAccess();
void testPagedVolumeChunkLocalAccess();
void testPagedVolumeChunkRandomAccess();
@ -72,6 +74,7 @@ private:
PolyVox::RawVolume<int32_t>* m_pRawVolume;
PolyVox::PagedVolume<int32_t>* m_pPagedVolume;
PolyVox::PagedVolume<int32_t>* m_pPagedVolumeHighMem;
PolyVox::PagedVolume<uint32_t>::Chunk* m_pPagedVolumeChunk;
};