C++11: Laid foundation for benchmark tests. We need more of them!

This commit is contained in:
Hans-Christian Ebke
2015-11-19 19:53:36 +01:00
parent 61fe9dabef
commit 3ed7079cb8
8 changed files with 83 additions and 34 deletions

View File

@@ -0,0 +1,11 @@
set (SOURCES "")
list (APPEND SOURCES
main.cpp
VectorT_new.cpp
VectorT_legacy.cpp
)
add_executable(OMBenchmark ${SOURCES})
set_target_properties(OMBenchmark PROPERTIES
INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/..")
target_link_libraries(OMBenchmark benchmark OpenMeshCore)

29
src/Benchmark/VectorT.cpp Normal file
View File

@@ -0,0 +1,29 @@
/*
* VectorT.cpp
*
* Created on: Nov 19, 2015
* Author: ebke
*/
#ifndef BMPREFIX
#error "Do not compile directly."
#endif
#define ASSEMBLE_(PREFIX, SUFFIX) PREFIX ## SUFFIX
#define ASSEMBLE(PREFIX, SUFFIX) ASSEMBLE_(PREFIX, SUFFIX)
#define MYBENCHMARK(NAME) BENCHMARK(NAME)
static void ASSEMBLE(BMPREFIX, Vec3f_add_compare)(benchmark::State& state) {
OpenMesh::Vec3f v1(0, 0, 0);
OpenMesh::Vec3f v2(1000, 1000, 1000);
while (state.KeepRunning()) {
v1 += OpenMesh::Vec3f(1.1, 1.2, 1.3);
v2 -= OpenMesh::Vec3f(1.1, 1.2, 1.3);
if (v1 == v2) {
v1 -= v2;
v2 += v1;
}
}
}
MYBENCHMARK (ASSEMBLE(BMPREFIX, Vec3f_add_compare));

View File

@@ -0,0 +1,14 @@
/*
* VectorT_legacy.cpp
*
* Created on: Nov 19, 2015
* Author: ebke
*/
#include <benchmark/benchmark_api.h>
#define OPENMESH_VECTOR_LEGACY
#include <OpenMesh/Core/Geometry/VectorT.hh>
#define BMPREFIX Legacy_
#include "VectorT.cpp"

View File

@@ -0,0 +1,12 @@
/*
* VectorT_new.cpp
*
* Created on: Nov 19, 2015
* Author: ebke
*/
#include <benchmark/benchmark_api.h>
#include <OpenMesh/Core/Geometry/VectorT.hh>
#define BMPREFIX CPP11_
#include "VectorT.cpp"

10
src/Benchmark/main.cpp Normal file
View File

@@ -0,0 +1,10 @@
/*
* main.cpp
*
* Created on: Nov 19, 2015
* Author: ebke
*/
#include <benchmark/benchmark_api.h>
BENCHMARK_MAIN();