Browse Source

Math: hmm, why this isn't in the FunctionsBenchmark, then?

Probably because it predates it.
pull/481/head
Vladimír Vondruš 6 years ago
parent
commit
89e3067009
  1. 33
      src/Magnum/Math/Test/FunctionsBenchmark.cpp
  2. 30
      src/Magnum/Math/Test/FunctionsTest.cpp

33
src/Magnum/Math/Test/FunctionsBenchmark.cpp

@ -45,6 +45,9 @@ struct FunctionsBenchmark: Corrade::TestSuite::Tester {
void sqrtSseFromInverted(); void sqrtSseFromInverted();
void sqrtInvertedSse(); void sqrtInvertedSse();
#endif #endif
void sinCosSeparate();
void sinCosCombined();
}; };
FunctionsBenchmark::FunctionsBenchmark() { FunctionsBenchmark::FunctionsBenchmark() {
@ -60,9 +63,14 @@ FunctionsBenchmark::FunctionsBenchmark() {
&FunctionsBenchmark::sqrtInvertedSse, &FunctionsBenchmark::sqrtInvertedSse,
#endif #endif
}, 500); }, 500);
addBenchmarks({&FunctionsBenchmark::sinCosSeparate,
&FunctionsBenchmark::sinCosCombined}, 100);
} }
typedef Math::Constants<Float> Constants; typedef Math::Constants<Float> Constants;
typedef Math::Deg<Float> Deg;
typedef Math::Rad<Float> Rad;
enum: std::size_t { Repeats = 100000 }; enum: std::size_t { Repeats = 100000 };
@ -182,9 +190,32 @@ void FunctionsBenchmark::sqrtInvertedSse() {
CORRADE_COMPARE_WITH(a, 1.0f, CORRADE_COMPARE_WITH(a, 1.0f,
Corrade::TestSuite::Compare::around(0.0003f)); Corrade::TestSuite::Compare::around(0.0003f));
} }
#endif #endif
void FunctionsBenchmark::sinCosSeparate() {
Float sin{}, cos{}, a{};
CORRADE_BENCHMARK(1000) {
sin += Math::sin(Rad(a));
cos += Math::cos(Rad(a));
a += 0.1f;
}
CORRADE_COMPARE_AS(a, 10.0f, Corrade::TestSuite::Compare::Greater);
}
void FunctionsBenchmark::sinCosCombined() {
Float sin{}, cos{}, a{};
CORRADE_BENCHMARK(1000) {
auto sincos = Math::sincos(Rad(a));
sin += sincos.first;
cos += sincos.second;
a += 0.1f;
}
CORRADE_COMPARE_AS(a, 10.0f, Corrade::TestSuite::Compare::Greater);
}
}}}} }}}}
CORRADE_TEST_MAIN(Magnum::Math::Test::FunctionsBenchmark) CORRADE_TEST_MAIN(Magnum::Math::Test::FunctionsBenchmark)

30
src/Magnum/Math/Test/FunctionsTest.cpp

@ -26,7 +26,6 @@
#include <sstream> #include <sstream>
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include <Corrade/TestSuite/Compare/Numeric.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h>
#include "Magnum/Math/Functions.h" #include "Magnum/Math/Functions.h"
@ -85,9 +84,6 @@ struct FunctionsTest: Corrade::TestSuite::Tester {
void trigonometric(); void trigonometric();
void trigonometricWithBase(); void trigonometricWithBase();
template<class T> void sincos(); template<class T> void sincos();
void sinCosSeparateBenchmark();
void sinCosCombinedBenchmark();
}; };
using namespace Literals; using namespace Literals;
@ -156,9 +152,6 @@ FunctionsTest::FunctionsTest() {
&FunctionsTest::sincos<long double>, &FunctionsTest::sincos<long double>,
#endif #endif
}); });
addBenchmarks({&FunctionsTest::sinCosSeparateBenchmark,
&FunctionsTest::sinCosCombinedBenchmark}, 100);
} }
void FunctionsTest::powIntegral() { void FunctionsTest::powIntegral() {
@ -605,29 +598,6 @@ template<class T> void FunctionsTest::sincos() {
CORRADE_COMPARE(Math::sincos(Math::Deg<T>(T(30.0))).second, T(0.866025403784438647l)); CORRADE_COMPARE(Math::sincos(Math::Deg<T>(T(30.0))).second, T(0.866025403784438647l));
} }
void FunctionsTest::sinCosSeparateBenchmark() {
Float sin{}, cos{}, a{};
CORRADE_BENCHMARK(1000) {
sin += Math::sin(Rad(a));
cos += Math::cos(Rad(a));
a += 0.1f;
}
CORRADE_COMPARE_AS(a, 10.0f, Corrade::TestSuite::Compare::Greater);
}
void FunctionsTest::sinCosCombinedBenchmark() {
Float sin{}, cos{}, a{};
CORRADE_BENCHMARK(1000) {
auto sincos = Math::sincos(Rad(a));
sin += sincos.first;
cos += sincos.second;
a += 0.1f;
}
CORRADE_COMPARE_AS(a, 10.0f, Corrade::TestSuite::Compare::Greater);
}
}}}} }}}}
CORRADE_TEST_MAIN(Magnum::Math::Test::FunctionsTest) CORRADE_TEST_MAIN(Magnum::Math::Test::FunctionsTest)

Loading…
Cancel
Save