Skip to content

Commit 8422c69

Browse files
codspeed-hq[bot]CopilotAlex-PLACET
authored
Add CodSpeed continuous performance testing (#2919)
This PR integrates [CodSpeed](https://codspeed.io) for continuous performance monitoring of xtensor's existing benchmark suite. ## What changed **`benchmark/CMakeLists.txt`** -- The Google Benchmark dependency is replaced with [CodSpeed's compatibility layer](https://github.com/CodSpeedHQ/codspeed-cpp), which wraps Google Benchmark with CodSpeed instrumentation. When `CODSPEED_MODE` is not set (or set to `off`), the build behaves identically to upstream Google Benchmark. Two additional changes are made for CodSpeed compatibility: - `-march=native` is conditionally skipped in simulation mode, since valgrind does not support all native instruction sets. - The build type is set to `RelWithDebInfo` (instead of `Release`) when CodSpeed is active, to include debug symbols for flame graph profiling. **`.github/workflows/codspeed.yml`** -- A new GitHub Actions workflow that builds and runs the full benchmark suite (160+ benchmarks) under CodSpeed's CPU simulation instrument on every push to `master` and on pull requests. The workflow uses OIDC authentication and follows the same dependency setup (micromamba, xsimd) as the existing `benchmarks.yml`. **`README.md`** -- Added the CodSpeed badge. ## How it works CodSpeed's simulation mode runs each benchmark once through a CPU instruction counter (valgrind-based), producing deterministic measurements that are independent of CI environment load. This makes performance regressions detectable on standard `ubuntu-latest` runners without dedicated hardware. ## Next steps 1. Install the [CodSpeed GitHub App](https://github.com/apps/codspeed) on this repository to enable performance reports on pull requests. 2. After merging, CodSpeed will automatically create a performance baseline from the `master` branch. 3. Subsequent PRs will receive performance comparisons showing regressions and improvements. --------- Co-authored-by: codspeed-hq[bot] <117304815+codspeed-hq[bot]@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Alex-PLACET <2400067+Alex-PLACET@users.noreply.github.com>
1 parent 849665a commit 8422c69

3 files changed

Lines changed: 70 additions & 8 deletions

File tree

.github/workflows/codspeed.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: CodSpeed
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
# Allow CodSpeed to trigger backtest performance analysis
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
id-token: write
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
defaults:
19+
run:
20+
shell: bash -e -l {0}
21+
22+
jobs:
23+
benchmarks:
24+
name: Run benchmarks
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v6
29+
30+
- name: Set conda environment
31+
uses: mamba-org/setup-micromamba@main
32+
with:
33+
environment-name: myenv
34+
environment-file: environment-dev.yml
35+
init-shell: bash
36+
cache-downloads: true
37+
38+
- name: Build benchmarks
39+
run: |
40+
cmake -G Ninja -Bbuild \
41+
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
42+
-DBUILD_BENCHMARK=ON \
43+
-DXTENSOR_USE_XSIMD=ON \
44+
-DCODSPEED_MODE=simulation
45+
cmake --build build --target benchmark_xtensor --parallel 8
46+
47+
- name: Run benchmarks
48+
uses: CodSpeedHQ/action@v4
49+
with:
50+
mode: simulation
51+
run: ./build/benchmark/benchmark_xtensor

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[![Doxygen -> gh-pages](https://github.com/xtensor-stack/xtensor/workflows/gh-pages/badge.svg)](https://xtensor-stack.github.io/xtensor)
88
[![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/xtensor-stack/xtensor/stable?filepath=notebooks%2Fxtensor.ipynb)
99
[![Zulip](https://img.shields.io/badge/social_chat-zulip-blue.svg)](https://xtensor.zulipchat.com/#narrow/channel/539553-Ask-anything)
10+
[![CodSpeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/xtensor-stack/xtensor?utm_source=badge)
1011

1112
Multi-dimensional arrays with broadcasting and lazy computing.
1213

benchmark/CMakeLists.txt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,26 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
1616
set(XTENSOR_INCLUDE_DIR ${xtensor_INCLUDE_DIRS})
1717
endif ()
1818

19-
message(STATUS "Forcing tests build type to Release")
20-
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
19+
if(CODSPEED_MODE AND NOT CODSPEED_MODE STREQUAL "off")
20+
message(STATUS "CodSpeed mode enabled (${CODSPEED_MODE}) - using RelWithDebInfo build type")
21+
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
22+
else()
23+
message(STATUS "Forcing tests build type to Release")
24+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
25+
endif()
2126

2227
include(CheckCXXCompilerFlag)
2328

2429
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
2530

2631
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
27-
CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported)
28-
if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march")
29-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
32+
# Skip -march=native for CodSpeed simulation mode (valgrind does not
33+
# support all native instruction sets)
34+
if(NOT (CODSPEED_MODE STREQUAL "simulation"))
35+
CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported)
36+
if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march")
37+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
38+
endif()
3039
endif()
3140
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g -Wunused-parameter -Wextra -Wreorder")
3241

@@ -80,13 +89,14 @@ if(DOWNLOAD_GBENCHMARK OR GBENCHMARK_SRC_DIR)
8089
GIT_TAG main)
8190

8291
FetchContent_Declare(googlebenchmark
83-
GIT_REPOSITORY https://github.com/google/benchmark.git
84-
GIT_TAG main) # need main for benchmark::benchmark
92+
GIT_REPOSITORY https://github.com/CodSpeedHQ/codspeed-cpp.git
93+
GIT_TAG main
94+
SOURCE_SUBDIR google_benchmark)
8595

8696
FetchContent_MakeAvailable(
8797
googletest
8898
googlebenchmark)
89-
set(GBENCHMARK_INCLUDE_DIRS "${googlebenchmark_SOURCE_DIR}/include")
99+
set(GBENCHMARK_INCLUDE_DIRS "${googlebenchmark_SOURCE_DIR}/google_benchmark/include")
90100
set(GBENCHMARK_LIBRARIES benchmark)
91101
else()
92102
find_package(benchmark REQUIRED)

0 commit comments

Comments
 (0)