From aff85ce9257dc8fe6abca11b83b533452c4b43cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 Sep 2016 16:07:27 +0200 Subject: [PATCH] MeshTools: port the dead benchmark code to Corrade TestSuite. --- src/Magnum/MeshTools/Test/CMakeLists.txt | 2 +- .../SubdivideRemoveDuplicatesBenchmark.cpp | 83 +++++++++++-------- .../Test/SubdivideRemoveDuplicatesBenchmark.h | 50 ----------- 3 files changed, 48 insertions(+), 87 deletions(-) delete mode 100644 src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.h diff --git a/src/Magnum/MeshTools/Test/CMakeLists.txt b/src/Magnum/MeshTools/Test/CMakeLists.txt index 5a324d4b6..91c8e60e1 100644 --- a/src/Magnum/MeshTools/Test/CMakeLists.txt +++ b/src/Magnum/MeshTools/Test/CMakeLists.txt @@ -31,7 +31,7 @@ corrade_add_test(MeshToolsGenerateFlatNormalsTest GenerateFlatNormalsTest.cpp LI corrade_add_test(MeshToolsInterleaveTest InterleaveTest.cpp LIBRARIES Magnum) corrade_add_test(MeshToolsRemoveDuplicatesTest RemoveDuplicatesTest.cpp LIBRARIES Magnum) corrade_add_test(MeshToolsSubdivideTest SubdivideTest.cpp LIBRARIES Magnum) -# corrade_add_test(MeshToolsSubdivideRemoveDuplicatesBenchmark SubdivideRemoveDuplicatesBenchmark.h SubdivideRemoveDuplicatesBenchmark.cpp MagnumPrimitives) +corrade_add_test(MeshToolsSubdivideRemoveDuplicatesBenchmark SubdivideRemoveDuplicatesBenchmark.cpp LIBRARIES MagnumPrimitives) corrade_add_test(MeshToolsTipsifyTest TipsifyTest.cpp LIBRARIES MagnumMeshTools) corrade_add_test(MeshToolsTransformTest TransformTest.cpp LIBRARIES MagnumMeshTools) diff --git a/src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp b/src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp index 91cf0e786..af48b49b5 100644 --- a/src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp +++ b/src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp @@ -23,62 +23,73 @@ DEALINGS IN THE SOFTWARE. */ -#include "SubdivideRemoveDuplicatesBenchmark.h" +#include -#include - -#include "Magnum/Primitives/Icosphere.h" +#include "Magnum/Math/Vector4.h" +#include "Magnum/MeshTools/Duplicate.h" #include "Magnum/MeshTools/RemoveDuplicates.h" #include "Magnum/MeshTools/Subdivide.h" - -QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::SubdivideRemoveDuplicatesBenchmark) +#include "Magnum/Primitives/Icosphere.h" +#include "Magnum/Trade/MeshData3D.h" namespace Magnum { namespace MeshTools { namespace Test { +struct SubdivideRemoveDuplicatesBenchmark: TestSuite::Tester { + explicit SubdivideRemoveDuplicatesBenchmark(); + + void subdivide(); + void subdivideAndRemoveDuplicatesAfter(); + void subdivideAndRemoveDuplicatesInBetween(); +}; + +SubdivideRemoveDuplicatesBenchmark::SubdivideRemoveDuplicatesBenchmark() { + addBenchmarks({&SubdivideRemoveDuplicatesBenchmark::subdivide, + &SubdivideRemoveDuplicatesBenchmark::subdivideAndRemoveDuplicatesAfter, + &SubdivideRemoveDuplicatesBenchmark::subdivideAndRemoveDuplicatesInBetween}, 4, BenchmarkType::WallClock); +} + +namespace { + static Vector3 interpolator(const Vector3& a, const Vector3& b) { + return (a+b).normalized(); + } +} + void SubdivideRemoveDuplicatesBenchmark::subdivide() { - QBENCHMARK { - Primitives::Icosphere<0> icosphere; + CORRADE_BENCHMARK(3) { + Trade::MeshData3D icosphere = Primitives::Icosphere::solid(0); /* Subdivide 5 times */ - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + for(std::size_t i = 0; i != 5; ++i) + MeshTools::subdivide(icosphere.indices(), icosphere.positions(0), interpolator); } } -void SubdivideRemoveDuplicatesBenchmark::subdivideAndRemoveDuplicatesMeshAfter() { - QBENCHMARK { - Primitives::Icosphere<0> icosphere; +void SubdivideRemoveDuplicatesBenchmark::subdivideAndRemoveDuplicatesAfter() { + CORRADE_BENCHMARK(3) { + Trade::MeshData3D icosphere = Primitives::Icosphere::solid(0); /* Subdivide 5 times */ - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + for(std::size_t i = 0; i != 5; ++i) + MeshTools::subdivide(icosphere.indices(), icosphere.positions(0), interpolator); - MeshTools::removeDuplicates(*icosphere.indices(), *icosphere.positions(0)); + /* Remove duplicates after */ + icosphere.indices() = MeshTools::duplicate(icosphere.indices(), MeshTools::removeDuplicates(icosphere.positions(0))); } } -void SubdivideRemoveDuplicatesBenchmark::subdivideAndRemoveDuplicatesMeshBetween() { - QBENCHMARK { - Primitives::Icosphere<0> icosphere; +void SubdivideRemoveDuplicatesBenchmark::subdivideAndRemoveDuplicatesInBetween() { + CORRADE_BENCHMARK(3) { + Trade::MeshData3D icosphere = Primitives::Icosphere::solid(0); - /* Subdivide 5 times */ - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::removeDuplicates(*icosphere.indices(), *icosphere.positions(0)); - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::removeDuplicates(*icosphere.indices(), *icosphere.positions(0)); - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::removeDuplicates(*icosphere.indices(), *icosphere.positions(0)); - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::removeDuplicates(*icosphere.indices(), *icosphere.positions(0)); - MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::removeDuplicates(*icosphere.indices(), *icosphere.positions(0)); + /* Subdivide 5 times and remove duplicates during the operation */ + for(std::size_t i = 0; i != 5; ++i) { + MeshTools::subdivide(icosphere.indices(), icosphere.positions(0), interpolator); + icosphere.indices() = MeshTools::duplicate(icosphere.indices(), MeshTools::removeDuplicates(icosphere.positions(0))); + } } } }}} + +CORRADE_TEST_MAIN(Magnum::MeshTools::Test::SubdivideRemoveDuplicatesBenchmark) + diff --git a/src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.h b/src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.h deleted file mode 100644 index 1d6fba46c..000000000 --- a/src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef Magnum_MeshTools_Test_SubdivideRemoveDuplicatesBenchmark_h -#define Magnum_MeshTools_Test_SubdivideRemoveDuplicatesBenchmark_h -/* - This file is part of Magnum. - - Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 - Vladimír Vondruš - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -#include - -#include "Magnum/Magnum.h" - -namespace Magnum { namespace MeshTools { namespace Test { - -class SubdivideRemoveDuplicatesBenchmark: public QObject { - Q_OBJECT - - private slots: - void subdivide(); - void subdivideAndRemoveDuplicatesMeshAfter(); - void subdivideAndRemoveDuplicatesMeshBetween(); - - private: - static Magnum::Vector4 interpolator(const Magnum::Vector4& a, const Magnum::Vector4& b) { - return (a+b).xyz().normalized(); - } -}; - -}}} - -#endif