Skip to content

Commit 4bf1ffa

Browse files
committed
chore: now in cpp
1 parent 537a638 commit 4bf1ffa

File tree

17 files changed

+477
-1136
lines changed

17 files changed

+477
-1136
lines changed

.github/workflows/codspeed.yml

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,28 @@ permissions:
1414
jobs:
1515
benchmarks:
1616
name: Run benchmarks
17-
runs-on: codspeed-macro
17+
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v4
19+
- uses: actions/checkout@v5
2020

21-
- name: Setup Rust
22-
uses: dtolnay/rust-toolchain@stable
23-
with:
24-
toolchain: stable
25-
26-
- name: Cache cargo registry
27-
uses: actions/cache@v4
28-
with:
29-
path: ~/.cargo/registry
30-
key: cargo-registry-${{ runner.arch }}-${{ hashFiles('**/Cargo.lock') }}
31-
restore-keys: |
32-
cargo-registry-${{ runner.arch }}-
33-
34-
- name: Cache target directory
35-
uses: actions/cache@v4
36-
with:
37-
path: target
38-
key: cargo-target-${{ runner.arch }}-${{ hashFiles('**/Cargo.lock') }}
39-
restore-keys: |
40-
cargo-target-${{ runner.arch }}-
21+
- name: Install CMake and build tools
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y cmake build-essential
4125
42-
- name: Install cargo-codspeed
43-
run: cargo install cargo-codspeed --locked
26+
- name: Configure CMake
27+
run: |
28+
mkdir -p build
29+
cd build
30+
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCODSPEED_MODE=simulation ..
4431
4532
- name: Build benchmarks
46-
run: cargo codspeed build
33+
run: |
34+
cd build
35+
make -j$(nproc)
4736
4837
- name: Run benchmarks
4938
uses: CodSpeedHQ/action@v4
5039
with:
51-
mode: walltime
52-
run: cargo codspeed run
40+
mode: simulation
41+
run: ./build/particle_simulation_bench

.gitignore

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
# Rust build artifacts
2-
/target/
1+
# C++ build artifacts
2+
/build/
3+
/cmake-build-*/
4+
*.o
5+
*.a
6+
*.so
7+
*.dylib
8+
*.exe
39

410
# IDE files
511
.vscode/
@@ -11,4 +17,10 @@
1117
# OS files
1218
.DS_Store
1319
Thumbs.db
14-
target
20+
21+
# CMake
22+
CMakeCache.txt
23+
CMakeFiles/
24+
cmake_install.cmake
25+
Makefile
26+
build/

CMakeLists.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
project(cache_patterns VERSION 1.0.0 LANGUAGES CXX)
3+
4+
# Set C++ standard
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
8+
# Use RelWithDebInfo for debug symbols (important for CodSpeed profiling)
9+
if(NOT CMAKE_BUILD_TYPE)
10+
set(CMAKE_BUILD_TYPE RelWithDebInfo)
11+
endif()
12+
13+
# Include FetchContent for downloading dependencies
14+
include(FetchContent)
15+
16+
# Enable downloading dependencies for benchmark
17+
set(BENCHMARK_DOWNLOAD_DEPENDENCIES ON)
18+
19+
# Disable specific warnings for CodSpeed/Google Benchmark
20+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
21+
add_compile_options(-Wno-sign-conversion -Wno-error)
22+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
23+
add_compile_options(-Wno-sign-conversion -Wno-error)
24+
endif()
25+
26+
# Fetch CodSpeed's Google Benchmark compatibility layer
27+
FetchContent_Declare(
28+
google_benchmark
29+
GIT_REPOSITORY https://github.com/CodSpeedHQ/codspeed-cpp
30+
GIT_TAG main
31+
SOURCE_SUBDIR google_benchmark
32+
)
33+
34+
FetchContent_MakeAvailable(google_benchmark)
35+
36+
# Create library for particle simulation code
37+
add_library(cache_patterns_lib
38+
src/aos.cpp
39+
src/soa.cpp
40+
)
41+
42+
target_include_directories(cache_patterns_lib PUBLIC
43+
${CMAKE_CURRENT_SOURCE_DIR}/include
44+
)
45+
46+
# Create benchmark executable
47+
add_executable(particle_simulation_bench
48+
benchmarks/particle_simulation.cpp
49+
)
50+
51+
target_link_libraries(particle_simulation_bench
52+
cache_patterns_lib
53+
benchmark::benchmark
54+
)
55+
56+
target_include_directories(particle_simulation_bench PRIVATE
57+
${CMAKE_CURRENT_SOURCE_DIR}/include
58+
)

0 commit comments

Comments
 (0)