Commit 797e83f2 authored by Janis Born's avatar Janis Born

add benchmarks for non-fundamental Scalar types for VectorT

parent 8ce8d00b
Pipeline #61 passed with stage
...@@ -3,6 +3,7 @@ list (APPEND SOURCES ...@@ -3,6 +3,7 @@ list (APPEND SOURCES
main.cpp main.cpp
VectorT_new.cpp VectorT_new.cpp
VectorT_legacy.cpp VectorT_legacy.cpp
VectorT_dummy_data.cpp
) )
add_executable(OMBenchmark ${SOURCES}) add_executable(OMBenchmark ${SOURCES})
......
...@@ -129,3 +129,35 @@ MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_times_scalar), OpenMesh::Vec3d); ...@@ -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::Vec3f);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_times_scalar), OpenMesh::Vec4d); MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_times_scalar), OpenMesh::Vec4d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_times_scalar), OpenMesh::Vec4f); MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPOSTFIX, Vec_times_scalar), OpenMesh::Vec4f);
#include "VectorT_dummy_data.hpp"
template<class Vec>
static void ASSEMBLE(BMPOSTFIX, Vec_add_in_place)(benchmark::State& state) {
auto v = make_dummy_vector<Vec>();
while (state.KeepRunning()) {
v += v;
}
// Otherwise GCC will optimize everything away.
static double dummy = observe_dummy_vector(v);
static_cast<void>(dummy);
}
template<class Vec>
static void ASSEMBLE(BMPOSTFIX, Vec_add_temporary)(benchmark::State& state) {
auto v = make_dummy_vector<Vec>();
while (state.KeepRunning()) {
v = v + v;
}
// Otherwise GCC will optimize everything away.
static double dummy = observe_dummy_vector(v);
static_cast<void>(dummy);
}
typedef OpenMesh::VectorT<std::valarray<double>, 3> Vec3VAd;
typedef OpenMesh::VectorT<std::complex<double>, 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);
#include "VectorT_dummy_data.hpp"
template<> std::valarray<double> make_dummy_component() {
return std::valarray<double>(128);
}
#pragma once
#include <valarray>
#include <complex>
template<typename T>
T make_dummy_component() {
return T();
}
template<> std::valarray<double> make_dummy_component();
template<typename Vec>
Vec make_dummy_vector() {
return Vec(make_dummy_component<typename Vec::value_type>());
}
template<typename Scalar>
double observe_dummy_component(const Scalar& _s) {
return _s;
}
template<typename T>
double observe_dummy_component(const std::valarray<T>& _s) {
return _s.sum();
}
template<typename T>
double observe_dummy_component(const std::complex<T>& _s) {
return _s.real() + _s.imag();
}
template<typename Vec>
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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment