diff --git a/src/Benchmark/CMakeLists.txt b/src/Benchmark/CMakeLists.txt index 9332e561..59ae3c00 100644 --- a/src/Benchmark/CMakeLists.txt +++ b/src/Benchmark/CMakeLists.txt @@ -3,6 +3,7 @@ list (APPEND SOURCES main.cpp VectorT_new.cpp VectorT_legacy.cpp + VectorT_dummy_data.cpp ) add_executable(OMBenchmark ${SOURCES}) diff --git a/src/Benchmark/VectorT.cpp b/src/Benchmark/VectorT.cpp index 348915b5..54989d54 100644 --- a/src/Benchmark/VectorT.cpp +++ b/src/Benchmark/VectorT.cpp @@ -129,3 +129,35 @@ MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_times_scalar), OpenMesh::Vec3d); MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_times_scalar), OpenMesh::Vec3f); MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_times_scalar), OpenMesh::Vec4d); MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_times_scalar), OpenMesh::Vec4f); + +#include "VectorT_dummy_data.hpp" + +template +static void ASSEMBLE(BMPOSTFIX, Vec_add_in_place)(benchmark::State& state) { + auto v = make_dummy_vector(); + while (state.KeepRunning()) { + v += v; + } + // Otherwise GCC will optimize everything away. + static double dummy = observe_dummy_vector(v); + static_cast(dummy); +} + +template +static void ASSEMBLE(BMPOSTFIX, Vec_add_temporary)(benchmark::State& state) { + auto v = make_dummy_vector(); + while (state.KeepRunning()) { + v = v + v; + } + // Otherwise GCC will optimize everything away. + static double dummy = observe_dummy_vector(v); + static_cast(dummy); +} + +typedef OpenMesh::VectorT, 3> Vec3VAd; +typedef OpenMesh::VectorT, 3> Vec3Cd; + +MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_add_in_place), Vec3VAd); +MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_add_temporary), Vec3VAd); +MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_add_in_place), Vec3Cd); +MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_add_temporary), Vec3Cd); diff --git a/src/Benchmark/VectorT_dummy_data.cpp b/src/Benchmark/VectorT_dummy_data.cpp new file mode 100644 index 00000000..cb2ca113 --- /dev/null +++ b/src/Benchmark/VectorT_dummy_data.cpp @@ -0,0 +1,5 @@ +#include "VectorT_dummy_data.hpp" + +template<> std::valarray make_dummy_component() { + return std::valarray(128); +} diff --git a/src/Benchmark/VectorT_dummy_data.hpp b/src/Benchmark/VectorT_dummy_data.hpp new file mode 100644 index 00000000..62211c9d --- /dev/null +++ b/src/Benchmark/VectorT_dummy_data.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include +#include + +template +T make_dummy_component() { + return T(); +} + +template<> std::valarray make_dummy_component(); + +template +Vec make_dummy_vector() { + return Vec(make_dummy_component()); +} + +template +double observe_dummy_component(const Scalar& _s) { + return _s; +} + +template +double observe_dummy_component(const std::valarray& _s) { + return _s.sum(); +} + +template +double observe_dummy_component(const std::complex& _s) { + return _s.real() + _s.imag(); +} + +template +double observe_dummy_vector(const Vec& _vec) { + double result = 0.0; + for (int dim = 0; dim < _vec.dim(); ++dim) { + result += observe_dummy_component(_vec[dim]); + } + return result; +}