diff --git a/src/Magnum/MeshTools/Test/GenerateNormalsTest.cpp b/src/Magnum/MeshTools/Test/GenerateNormalsTest.cpp index 5fb54d437..5fed3ecce 100644 --- a/src/Magnum/MeshTools/Test/GenerateNormalsTest.cpp +++ b/src/Magnum/MeshTools/Test/GenerateNormalsTest.cpp @@ -32,8 +32,9 @@ #include #include -#include "Magnum/Math/Functions.h" +#include "Magnum/Math/FunctionsBatch.h" #include "Magnum/Math/Vector3.h" +#include "Magnum/MeshTools/Duplicate.h" #include "Magnum/MeshTools/GenerateNormals.h" #include "Magnum/Primitives/Cylinder.h" #include "Magnum/Trade/MeshData3D.h" @@ -56,6 +57,9 @@ struct GenerateNormalsTest: TestSuite::Tester { void smoothCylinder(); void smoothWrongCount(); void smoothIntoWrongSize(); + + void benchmarkFlat(); + void benchmarkSmooth(); }; GenerateNormalsTest::GenerateNormalsTest() { @@ -72,6 +76,9 @@ GenerateNormalsTest::GenerateNormalsTest() { &GenerateNormalsTest::smoothCylinder, &GenerateNormalsTest::smoothWrongCount, &GenerateNormalsTest::smoothIntoWrongSize}); + + addBenchmarks({&GenerateNormalsTest::benchmarkFlat, + &GenerateNormalsTest::benchmarkSmooth}, 150); } /* Two vertices connected by one edge, each wound in another direction */ @@ -338,6 +345,30 @@ void GenerateNormalsTest::smoothIntoWrongSize() { CORRADE_COMPARE(out.str(), "MeshTools::generateSmoothNormalsInto(): bad output size, expected 3 but got 4\n"); } +void GenerateNormalsTest::benchmarkFlat() { + Containers::Array positions = duplicate( + Containers::stridedArrayView(BeveledCubeIndices), + Containers::stridedArrayView(BeveledCubePositions)); + + Containers::Array normals{Containers::NoInit, positions.size()}; + CORRADE_BENCHMARK(10) { + generateFlatNormalsInto(positions, normals); + } + + CORRADE_COMPARE(Math::min(normals), (Vector3{-1.0f, -1.0f, -1.0f})); +} + +void GenerateNormalsTest::benchmarkSmooth() { + Containers::Array normals{Containers::NoInit, Containers::arraySize(BeveledCubePositions)}; + CORRADE_BENCHMARK(10) { + generateSmoothNormalsInto( + Containers::stridedArrayView(BeveledCubeIndices), + BeveledCubePositions, normals); + } + + CORRADE_COMPARE(Math::min(normals), (Vector3{-0.996072f, -0.997808f, -0.996072f})); +} + }}}} CORRADE_TEST_MAIN(Magnum::MeshTools::Test::GenerateNormalsTest)