Skip to content

Commit

Permalink
include Google Benchmark submodule, and add a benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
universenox authored and sdavtaker committed May 22, 2019
1 parent 5532037 commit d325952
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -1,3 +1,6 @@
[submodule "cmake-modules"]
path = cmake-modules
url = https://github.com/bilke/cmake-modules.git
[submodule "bench/benchmark"]
path = bench/benchmark
url = https://github.com/google/benchmark.git
7 changes: 7 additions & 0 deletions CMakeLists.txt
Expand Up @@ -44,3 +44,10 @@ set_target_properties(Boost.Real_headers PROPERTIES
EXCLUDE_FROM_ALL TRUE
EXCLUDE_FROM_DEFAULT_BUILD TRUE
LINKER_LANGUAGE CXX)

#Google Benchmark, turn on/off with -DBENCH=ON or OFF
find_package(Threads REQUIRED)
option(BENCH "Build benchmarks" ON)
if(BENCH)
add_subdirectory(bench)
endif()
18 changes: 18 additions & 0 deletions bench/CMakeLists.txt
@@ -0,0 +1,18 @@
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Suppressing benchmark's tests" FORCE)

add_subdirectory(benchmark)
include_directories(benchmark/include
include)

set(bench_list
addition_bench.cpp
)

add_executable(main_bench ${bench_list})


target_link_libraries(main_bench
benchmark
Boost.Real
${CMAKE_THREAD_LIBS_INIT}
)
19 changes: 19 additions & 0 deletions bench/addition_bench.cpp
@@ -0,0 +1,19 @@
#include <bench_helpers.hpp>
#include <benchmark/benchmark.h>
#include <real/real.hpp>
#include <iostream>

// this process uses an absurd amount of memory
// sums 10,000 reals, then evaluates.
static void BM_RealAddition10000(benchmark::State& state) {
boost::real::real a ("1.2");
boost::real::real c ("0");

for (auto i : state)
for (int i = 0; i < 10000; i++)
c += a;
std::cout << c << '\n';
}
BENCHMARK(BM_RealAddition10000);

BENCHMARK_MAIN();
1 change: 1 addition & 0 deletions bench/benchmark
Submodule benchmark added at 090fae
10 changes: 10 additions & 0 deletions bench/include/bench_helpers.hpp
@@ -0,0 +1,10 @@
#ifndef BOOST_REAL_BENCH_HELPERS_HPP
#define BOOST_REAL_BENCH_HELPERS_HPP


#include <real/real.hpp>

unsigned int boost::real::real::maximum_precision = 10;
unsigned int boost::real::real_algorithm::maximum_precision = 10;

#endif //BOOST_REAL_BENCH_HELPERS_HPP

0 comments on commit d325952

Please sign in to comment.