diff --git a/tests/TestArray.cpp b/tests/TestArray.cpp index 8dde377a..bf024061 100644 --- a/tests/TestArray.cpp +++ b/tests/TestArray.cpp @@ -29,6 +29,36 @@ freely, subject to the following restrictions: using namespace PolyVox; +template +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 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; diff --git a/tests/TestArray.h b/tests/TestArray.h index 2d3e5951..bd5425a6 100644 --- a/tests/TestArray.h +++ b/tests/TestArray.h @@ -33,6 +33,7 @@ class TestArray: public QObject private slots: void testCArraySpeed(); void testPolyVoxArraySpeed(); + void testPolyVoxArray2DSpeed(); void testReadWrite(); };