add benchmarks for non-fundamental Scalar types for VectorT
This commit is contained in:
@@ -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);
|
|||||||
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);
|
||||||
|
|||||||
5
src/Benchmark/VectorT_dummy_data.cpp
Normal file
5
src/Benchmark/VectorT_dummy_data.cpp
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#include "VectorT_dummy_data.hpp"
|
||||||
|
|
||||||
|
template<> std::valarray<double> make_dummy_component() {
|
||||||
|
return std::valarray<double>(128);
|
||||||
|
}
|
||||||
40
src/Benchmark/VectorT_dummy_data.hpp
Normal file
40
src/Benchmark/VectorT_dummy_data.hpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user