New array class is 50(!) times faster than the old one on raw read-write performance. It's also significantly simply.

This commit is contained in:
David Williams 2014-08-21 21:31:09 +02:00
parent d9f328cadb
commit 46358adfbc
2 changed files with 54 additions and 0 deletions

View File

@ -29,6 +29,36 @@ freely, subject to the following restrictions:
using namespace PolyVox;
template <typename ElementType>
class Array2D
{
public:
Array2D(uint32_t width, uint32_t height)
:m_uWidth(width)
,m_uHeight(height)
,m_pData(0)
{
m_pData = new ElementType[m_uWidth * m_uHeight];
}
~Array2D()
{
delete[] m_pData;
}
ElementType& operator()(uint32_t x, uint32_t y)
{
return m_pData[y * m_uWidth + x];
}
private:
uint32_t m_uWidth;
uint32_t m_uHeight;
ElementType* m_pData;
};
void TestArray::testCArraySpeed()
{
const int width = 128;
@ -75,6 +105,29 @@ void TestArray::testPolyVoxArraySpeed()
}
}
void TestArray::testPolyVoxArray2DSpeed()
{
const int width = 128;
const int height = 128;
Array2D<int> polyvoxArray(width,height);
QBENCHMARK
{
int ct = 1;
int expectedTotal = 0;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
polyvoxArray(x,y) = ct;
expectedTotal += polyvoxArray(x,y);
ct++;
}
}
}
}
void TestArray::testReadWrite()
{
int width = 5;

View File

@ -33,6 +33,7 @@ class TestArray: public QObject
private slots:
void testCArraySpeed();
void testPolyVoxArraySpeed();
void testPolyVoxArray2DSpeed();
void testReadWrite();
};