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:
parent
d9f328cadb
commit
46358adfbc
@ -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;
|
||||
|
@ -33,6 +33,7 @@ class TestArray: public QObject
|
||||
private slots:
|
||||
void testCArraySpeed();
|
||||
void testPolyVoxArraySpeed();
|
||||
void testPolyVoxArray2DSpeed();
|
||||
void testReadWrite();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user