Commit dbb4cf4d authored by Hans-Christian Ebke's avatar Hans-Christian Ebke
Browse files

Further templatized benchmarks. Testing Vec4* now as well.

parent fe3dfade
......@@ -14,13 +14,27 @@
#define MYBENCHMARK(NAME) BENCHMARK(NAME)
#define MYBENCHMARK_TEMPLATE(NAME, TYPE) BENCHMARK_TEMPLATE(NAME, TYPE)
template<class Vec>
static inline
typename std::enable_if<Vec::size_ == 3, Vec>::type
testVec() {
return Vec(1.1, 1.2, 1.3);
}
template<class Vec>
static inline
typename std::enable_if<Vec::size_ == 4, Vec>::type
testVec() {
return Vec(1.1, 1.2, 1.3, 1.4);
}
template<class Vec>
static void ASSEMBLE(BMPREFIX, Vec_add_compare)(benchmark::State& state) {
Vec v1(0, 0, 0);
Vec v2(1000, 1000, 1000);
Vec v1(0.0);
Vec v2(1000.0);
while (state.KeepRunning()) {
v1 += Vec(1.1, 1.2, 1.3);
v2 -= Vec(1.1, 1.2, 1.3);
v1 += testVec<Vec>();
v2 -= testVec<Vec>();
if (v1 == v2) {
v1 -= v2;
v2 += v1;
......@@ -33,14 +47,16 @@ static void ASSEMBLE(BMPREFIX, Vec_add_compare)(benchmark::State& state) {
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_add_compare), OpenMesh::Vec3d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_add_compare), OpenMesh::Vec3f);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_add_compare), OpenMesh::Vec4d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_add_compare), OpenMesh::Vec4f);
template<class Vec>
static void ASSEMBLE(BMPREFIX, Vec_cross_product)(benchmark::State& state) {
Vec v1(0, 0, 0);
Vec v2(1000, 1000, 1000);
Vec v1(0.0);
Vec v2(1000.0);
while (state.KeepRunning()) {
v1 += Vec(1.1, 1.2, 1.3);
v2 -= Vec(1.1, 1.2, 1.3);
v1 += testVec<Vec>();
v2 -= testVec<Vec>();
v1 = (v1 % v2);
}
// Just so nothing gets optimized away.
......@@ -53,12 +69,12 @@ MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_cross_product), OpenMesh::Vec3f);
template<class Vec>
static void ASSEMBLE(BMPREFIX, Vec_scalar_product)(benchmark::State& state) {
Vec v1(0, 0, 0);
Vec v2(1000, 1000, 1000);
Vec v1(0.0);
Vec v2(1000.0);
double acc = 0;
while (state.KeepRunning()) {
v1 += Vec(1.1, 1.2, 1.3);
v2 -= Vec(1.1, 1.2, 1.3);
v1 += testVec<Vec>();
v2 -= testVec<Vec>();
acc += (v1 | v2);
}
// Otherwise GCC will optimize everything away.
......@@ -68,13 +84,15 @@ static void ASSEMBLE(BMPREFIX, Vec_scalar_product)(benchmark::State& state) {
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_scalar_product), OpenMesh::Vec3d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_scalar_product), OpenMesh::Vec3f);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_scalar_product), OpenMesh::Vec4d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_scalar_product), OpenMesh::Vec4f);
template<class Vec>
static void ASSEMBLE(BMPREFIX, Vec_norm)(benchmark::State& state) {
Vec v1(0, 0, 0);
Vec v1(0.0);
double acc = 0;
while (state.KeepRunning()) {
v1 += Vec(1.1, 1.2, 1.3);
v1 += testVec<Vec>();
acc += v1.norm();
}
// Otherwise GCC will optimize everything away.
......@@ -84,3 +102,5 @@ static void ASSEMBLE(BMPREFIX, Vec_norm)(benchmark::State& state) {
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_norm), OpenMesh::Vec3d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_norm), OpenMesh::Vec3f);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_norm), OpenMesh::Vec4d);
MYBENCHMARK_TEMPLATE (ASSEMBLE(BMPREFIX, Vec_norm), OpenMesh::Vec4f);
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