Browse Source

MeshTools: port the dead benchmark code to Corrade TestSuite.

pull/175/merge
Vladimír Vondruš 10 years ago
parent
commit
aff85ce925
  1. 2
      src/Magnum/MeshTools/Test/CMakeLists.txt
  2. 83
      src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp
  3. 50
      src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.h

2
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)

83
src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp

@ -23,62 +23,73 @@
DEALINGS IN THE SOFTWARE.
*/
#include "SubdivideRemoveDuplicatesBenchmark.h"
#include <Corrade/TestSuite/Tester.h>
#include <QtTest/QTest>
#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)

50
src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.h

@ -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š <mosra@centrum.cz>
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 <QtCore/QObject>
#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
Loading…
Cancel
Save