C++11: Laid foundation for benchmark tests. We need more of them!
This commit is contained in:
@@ -88,6 +88,12 @@ add_subdirectory (src/OpenMesh/Core)
|
||||
add_subdirectory (src/OpenMesh/Tools)
|
||||
add_subdirectory (src/OpenMesh/Apps)
|
||||
|
||||
set(OPENMESH_BENCHMARK_DIR CACHE PATH "Source path of benchmark (https://github.com/google/benchmark).")
|
||||
if (OPENMESH_BENCHMARK_DIR)
|
||||
add_subdirectory(${OPENMESH_BENCHMARK_DIR} benchmark)
|
||||
add_subdirectory(src/Benchmark)
|
||||
endif()
|
||||
|
||||
# Do not build unit tests when build as external library
|
||||
if(${PROJECT_NAME} MATCHES "OpenMesh")
|
||||
add_subdirectory (src/Unittests)
|
||||
|
||||
11
src/Benchmark/CMakeLists.txt
Normal file
11
src/Benchmark/CMakeLists.txt
Normal 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
29
src/Benchmark/VectorT.cpp
Normal 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));
|
||||
14
src/Benchmark/VectorT_legacy.cpp
Normal file
14
src/Benchmark/VectorT_legacy.cpp
Normal 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"
|
||||
12
src/Benchmark/VectorT_new.cpp
Normal file
12
src/Benchmark/VectorT_new.cpp
Normal 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
10
src/Benchmark/main.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* main.cpp
|
||||
*
|
||||
* Created on: Nov 19, 2015
|
||||
* Author: ebke
|
||||
*/
|
||||
|
||||
#include <benchmark/benchmark_api.h>
|
||||
|
||||
BENCHMARK_MAIN();
|
||||
@@ -60,7 +60,7 @@
|
||||
// macro expansion and preprocessor defines
|
||||
// don't work properly.
|
||||
|
||||
#if __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
#if (__cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENMESH_VECTOR_LEGACY)
|
||||
#include "Vector11T.hh"
|
||||
#else
|
||||
#ifndef DOXYGEN
|
||||
|
||||
@@ -97,28 +97,6 @@ public:
|
||||
/// default constructor creates uninitialized values.
|
||||
inline VectorT() {}
|
||||
|
||||
#if __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
explicit inline VectorT(const Scalar &v) {
|
||||
vectorize(v);
|
||||
}
|
||||
|
||||
template<typename... T,
|
||||
typename = typename std::enable_if<sizeof...(T) == DIM>::type,
|
||||
typename = typename std::enable_if<are_convertible_to<Scalar, T...>::value>::type>
|
||||
constexpr VectorT(T... vs) : Base { static_cast<Scalar>(vs)...}
|
||||
{ }
|
||||
|
||||
template<int D = DIM, typename = typename std::enable_if<D == DIM>::type>
|
||||
typename std::enable_if<D==4, VectorT>::type
|
||||
homogenized() const {
|
||||
return VectorT(
|
||||
Base::values_[0]/Base::values_[3],
|
||||
Base::values_[1]/Base::values_[3],
|
||||
Base::values_[2]/Base::values_[3],
|
||||
1);
|
||||
}
|
||||
|
||||
#else
|
||||
/// special constructor for 1D vectors
|
||||
explicit inline VectorT(const Scalar& v) {
|
||||
// assert(DIM==1);
|
||||
@@ -165,7 +143,6 @@ public:
|
||||
Base::values_[0]=v0; Base::values_[1]=v1; Base::values_[2]=v2;
|
||||
Base::values_[3]=v3; Base::values_[4]=v4; Base::values_[5]=v5;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/// construct from a value array (explicit)
|
||||
@@ -210,21 +187,11 @@ public:
|
||||
// /// cast to const Scalar array
|
||||
// inline operator const Scalar*() const { return Base::values_; }
|
||||
|
||||
#if __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
/// access to Scalar array
|
||||
inline Scalar* data() { return Base::values_.data(); }
|
||||
|
||||
/// access to const Scalar array
|
||||
inline const Scalar*data() const { return Base::values_.data(); }
|
||||
#else
|
||||
/// access to Scalar array
|
||||
inline Scalar* data() { return Base::values_; }
|
||||
|
||||
/// access to const Scalar array
|
||||
inline const Scalar*data() const { return Base::values_; }
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------- element access
|
||||
|
||||
Reference in New Issue
Block a user