From 8269d5b3a608a24911c8430b0cfe2a79ed8f8ea8 Mon Sep 17 00:00:00 2001 From: Christopher Weyand Date: Wed, 11 Oct 2023 10:50:35 +0200 Subject: [PATCH] change google benchmark include --- CMakeLists.txt | 1 + source/benchmarks/CMakeLists.txt | 26 +++++----------------- source/benchmarks/bmi-benchmarks/main.cpp | 2 +- source/benchmarks/math-benchmarks/main.cpp | 7 ++---- source/tests/CMakeLists.txt | 1 - 5 files changed, 10 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dc86de..46b219a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") # Include modules provided by cmake include(GenerateExportHeader) include(GoogleTest) +include(FetchContent) enable_testing() diff --git a/source/benchmarks/CMakeLists.txt b/source/benchmarks/CMakeLists.txt index 04e86e9..8fb9fc1 100644 --- a/source/benchmarks/CMakeLists.txt +++ b/source/benchmarks/CMakeLists.txt @@ -4,29 +4,15 @@ # # Build google benchmark -download_project(PROJ googlebenchmark - GIT_REPOSITORY https://github.com/google/benchmark.git - GIT_TAG master - UPDATE_DISCONNECTED 1 +FetchContent_Declare( + benchmark + GIT_REPOSITORY https://github.com/google/benchmark.git + GIT_TAG v1.8.3 + FIND_PACKAGE_ARGS ) - set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE) set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE) -set(BUILD_SHARED_LIBS OFF) -add_subdirectory( - ${googlebenchmark_SOURCE_DIR} - ${googlebenchmark_BINARY_DIR}) - -# configure targets -foreach(target benchmark benchmark_main) - set_target_properties(${target} PROPERTIES - FOLDER "${IDE_FOLDER}" - RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} - LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} - ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} - ) -endforeach() - +FetchContent_MakeAvailable(benchmark) # add onw benchmarks add_subdirectory(bmi-benchmarks) diff --git a/source/benchmarks/bmi-benchmarks/main.cpp b/source/benchmarks/bmi-benchmarks/main.cpp index 93cce35..9535f20 100644 --- a/source/benchmarks/bmi-benchmarks/main.cpp +++ b/source/benchmarks/bmi-benchmarks/main.cpp @@ -16,7 +16,7 @@ static void BM_deposit(benchmark::State& state) { for(auto _ : state) { for(const auto& c: values) { - const auto x = Impl::deposit(c); + auto x = Impl::deposit(c); benchmark::DoNotOptimize(x); } } diff --git a/source/benchmarks/math-benchmarks/main.cpp b/source/benchmarks/math-benchmarks/main.cpp index 4756dec..b261610 100644 --- a/source/benchmarks/math-benchmarks/main.cpp +++ b/source/benchmarks/math-benchmarks/main.cpp @@ -21,7 +21,7 @@ double pow1000(double x) { return pow(1000.0, x);} const T step = 1e10; \ for(auto _ : state) { \ benchmark::DoNotOptimize(x); \ - const auto tmp = X(x); \ + auto tmp = X(x); \ benchmark::DoNotOptimize(tmp); \ } \ } \ @@ -64,9 +64,6 @@ struct EdgeProbBase { EdgeProbBase(double T, double R, double maxProb) : m_T(T), m_R(R), m_maxProb(maxProb) {} bool operator() (const Point& a, const Point& b, double uni_rnd) const noexcept { - benchmark::DoNotOptimize(a); - benchmark::DoNotOptimize(b); - benchmark::DoNotOptimize(uni_rnd); return false; } @@ -120,7 +117,7 @@ static void BM_edge_prob(benchmark::State& state) { for(auto _ : state) { i = i < n - 2 ? i + 2 : 0; - const auto is_edge = base(points[i], points[i+1], dist_prob(prng)); + auto is_edge = base(points[i], points[i+1], dist_prob(prng)); benchmark::DoNotOptimize(is_edge); } } diff --git a/source/tests/CMakeLists.txt b/source/tests/CMakeLists.txt index 21e53a3..fccac7e 100644 --- a/source/tests/CMakeLists.txt +++ b/source/tests/CMakeLists.txt @@ -5,7 +5,6 @@ # Get gtest/gmock -include(FetchContent) FetchContent_Declare( GTest GIT_REPOSITORY https://github.com/google/googletest.git