File tree Expand file tree Collapse file tree 7 files changed +57
-4
lines changed
Expand file tree Collapse file tree 7 files changed +57
-4
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ Checks: >
1111
1212UseColor : true
1313WarningsAsErrors : ' '
14- HeaderFilterRegex : ' .* '
14+ HeaderFilterRegex : ' ^(include|src|tests|benchmarks)/ '
1515FormatStyle : file
1616CheckOptions :
1717 - key : modernize-use-nullptr.NullMacros
Original file line number Diff line number Diff line change @@ -9,9 +9,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
99set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
1010
1111# Options
12- option (ENABLE_TESTING "Build tests" ON )
13- option (BUILD_APP "Build the demo application" ON )
14- option (BUILD_DOCS "Enable documentation via Doxygen" ON )
12+ option (ENABLE_TESTING "Build tests" ON )
13+ option (ENABLE_BENCHMARKS "Build benchmarks" ON )
14+ option (BUILD_APP "Build the demo application" ON )
15+ option (BUILD_DOCS "Build documentation via Doxygen" ON )
1516
1617# Add custom "Sanitize" build type
1718if (CMAKE_CONFIGURATION_TYPES )
@@ -42,6 +43,10 @@ if(ENABLE_TESTING)
4243 add_subdirectory (tests)
4344endif ()
4445
46+ if (ENABLE_BENCHMARKS)
47+ add_subdirectory (benchmarks)
48+ endif ()
49+
4550# === Docs ===
4651if (BUILD_DOCS)
4752 include (tools/Doxygen)
Original file line number Diff line number Diff line change 1212 "binaryDir" : " ${sourceDir}/build/${presetName}" ,
1313 "cacheVariables" : {
1414 "ENABLE_TESTING" : " ON" ,
15+ "ENABLE_BENCHMARKS" : " ON" ,
1516 "BUILD_APP" : " ON" ,
1617 "BUILD_DOCS" : " ON" ,
1718 "CMAKE_EXPORT_COMPILE_COMMANDS" : " ON"
Original file line number Diff line number Diff line change 1+ include (FetchContent)
2+
3+ set (BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark library tests" )
4+
5+ FetchContent_Declare(
6+ benchmark
7+ URL https://github.com/google/benchmark/archive/refs/tags/v1.9.4.zip
8+ DOWNLOAD_EXTRACT_TIMESTAMP TRUE # Prevents timestamp-related rebuild issues
9+ )
10+
11+ FetchContent_MakeAvailable(benchmark)
12+
13+ add_executable (benchmarks
14+ bench_arithmetic.cpp
15+ )
16+
17+ target_link_libraries (benchmarks
18+ PRIVATE benchmark::benchmark benchmark::benchmark_main ${PROJECT_NAME} ::math
19+ )
20+
21+ enable_strict_warnings(benchmarks)
Original file line number Diff line number Diff line change 1+ #include < benchmark/benchmark.h>
2+
3+ #include " math/arithmetic.hpp"
4+
5+ static void BM_Add (benchmark::State& state)
6+ {
7+ for (auto _ : state) // NOLINT
8+ {
9+ benchmark::DoNotOptimize (math::add (1 , 2 )); // NOLINT
10+ }
11+ }
12+
13+ static void BM_Subtract (benchmark::State& state)
14+ {
15+ for (auto _ : state) // NOLINT
16+ {
17+ benchmark::DoNotOptimize (math::subtract (5 , 3 )); // NOLINT
18+ }
19+ }
20+
21+ BENCHMARK (BM_Add);
22+ BENCHMARK (BM_Subtract);
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ if(CLANG_FORMAT_EXE)
1212 "${CMAKE_SOURCE_DIR} /tests/**/*.cpp"
1313 "${CMAKE_SOURCE_DIR} /tests/*.hpp"
1414 "${CMAKE_SOURCE_DIR} /tests/**/*.hpp"
15+ "${CMAKE_SOURCE_DIR} /benchmarks/*.cpp"
16+ "${CMAKE_SOURCE_DIR} /benchmarks/**/*.cpp"
1517 )
1618
1719 add_custom_target (clang-format
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ if(CLANG_TIDY_EXE)
66 "${CMAKE_SOURCE_DIR} /src/**/*.cpp"
77 "${CMAKE_SOURCE_DIR} /tests/*.cpp"
88 "${CMAKE_SOURCE_DIR} /tests/**/*.cpp"
9+ "${CMAKE_SOURCE_DIR} /benchmarks/*.cpp"
10+ "${CMAKE_SOURCE_DIR} /benchmarks/**/*.cpp"
911 )
1012
1113 add_custom_target (clang-tidy
You can’t perform that action at this time.
0 commit comments