Skip to content

Commit

Permalink
Add vector benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-jones committed Jun 27, 2024
1 parent faacc19 commit aa28a2f
Show file tree
Hide file tree
Showing 2 changed files with 386 additions and 4 deletions.
44 changes: 40 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
cmake_minimum_required(VERSION 3.12)
project(cramer VERSION 1.0.0 LANGUAGES CXX)
project(cramer VERSION 0.1.0 LANGUAGES CXX)

# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Enable AddressSanitizer and Coverage
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fsanitize=address -fprofile-arcs -ftest-coverage")
# Option for enabling code coverage
option(ENABLE_COVERAGE "Enable coverage reporting" OFF)

# Configure compiler flags
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# Add debug-specific options here
add_compile_options(-g -O0)

if(ENABLE_COVERAGE)
add_compile_options(--coverage -fprofile-arcs -ftest-coverage)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
endif()
endif()

# Enable AddressSanitizer
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fsanitize=address")

# Find dependencies
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -36,3 +51,24 @@ enable_testing()

# Add the tests subdirectory
add_subdirectory(tests)

# Benchmarking
# Fetch and build Google Benchmark
include(FetchContent)
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.6.1
)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(benchmark)

# Add benchmark executable
add_executable(benchmark_vector benchmarks/benchmark_vector.cpp)
target_link_libraries(benchmark_vector PRIVATE
cramer
benchmark::benchmark
)

# Make sure benchmarks are built by default
add_custom_target(build_all ALL DEPENDS cramer benchmark_vector)
Loading

0 comments on commit aa28a2f

Please sign in to comment.