diff --git a/src/Magnum/Math/Algorithms/Test/KahanSumTest.cpp b/src/Magnum/Math/Algorithms/Test/KahanSumTest.cpp index 8efe8140c..7cacabbee 100644 --- a/src/Magnum/Math/Algorithms/Test/KahanSumTest.cpp +++ b/src/Magnum/Math/Algorithms/Test/KahanSumTest.cpp @@ -24,7 +24,7 @@ */ #include -#include +#include #include #include "Magnum/Magnum.h" @@ -39,8 +39,9 @@ struct KahanSumTest: TestSuite::Tester { void integers(); void iterative(); - void accumulate100k(); - void kahan100k(); + void accumulate100kFloats(); + void accumulate100kDoubles(); + void kahan100kFloats(); }; @@ -49,8 +50,9 @@ KahanSumTest::KahanSumTest() { &KahanSumTest::integers, &KahanSumTest::iterative}); - addBenchmarks({&KahanSumTest::accumulate100k, - &KahanSumTest::kahan100k}, 50); + addBenchmarks({&KahanSumTest::accumulate100kFloats, + &KahanSumTest::accumulate100kDoubles, + &KahanSumTest::kahan100kFloats}, 50); } /* Custom iterator class to avoid allocating half a gigabyte for hundred @@ -140,8 +142,8 @@ void KahanSumTest::iterative() { } } -void KahanSumTest::accumulate100k() { - std::vector data(100000, 1.0f); +void KahanSumTest::accumulate100kFloats() { + Containers::Array data(Containers::DirectInit, 100000, 1.0f); volatile Float a; /* to avoid optimizing the loop out */ CORRADE_BENCHMARK(10) { @@ -151,8 +153,19 @@ void KahanSumTest::accumulate100k() { CORRADE_COMPARE(Float(a), 100000.0f); } -void KahanSumTest::kahan100k() { - std::vector data(100000, 1.0f); +void KahanSumTest::accumulate100kDoubles() { + Containers::Array data(Containers::DirectInit, 100000, 1.0); + + volatile Double a; /* to avoid optimizing the loop out */ + CORRADE_BENCHMARK(10) { + a = std::accumulate(data.begin(), data.end(), 0.0); + } + + CORRADE_COMPARE(Double(a), 100000.0); +} + +void KahanSumTest::kahan100kFloats() { + Containers::Array data(Containers::DirectInit, 100000, 1.0f); volatile Float a; /* to avoid optimizing the loop out */ CORRADE_BENCHMARK(10) {