diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml new file mode 100644 index 000000000..9e2c5999c --- /dev/null +++ b/.github/workflows/codspeed.yml @@ -0,0 +1,51 @@ +name: CodSpeed + +on: + push: + branches: [master] + pull_request: + # Allow CodSpeed to trigger backtest performance analysis + workflow_dispatch: + +permissions: + contents: read + id-token: write + +concurrency: + group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }} + cancel-in-progress: true + +defaults: + run: + shell: bash -e -l {0} + +jobs: + benchmarks: + name: Run benchmarks + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Set conda environment + uses: mamba-org/setup-micromamba@main + with: + environment-name: myenv + environment-file: environment-dev.yml + init-shell: bash + cache-downloads: true + + - name: Build benchmarks + run: | + cmake -G Ninja -Bbuild \ + -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \ + -DBUILD_BENCHMARK=ON \ + -DXTENSOR_USE_XSIMD=ON \ + -DCODSPEED_MODE=simulation + cmake --build build --target benchmark_xtensor --parallel 8 + + - name: Run benchmarks + uses: CodSpeedHQ/action@v4 + with: + mode: simulation + run: ./build/benchmark/benchmark_xtensor diff --git a/README.md b/README.md index 0813d3438..19c5f9fe1 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ [![Doxygen -> gh-pages](https://github.com/xtensor-stack/xtensor/workflows/gh-pages/badge.svg)](https://xtensor-stack.github.io/xtensor) [![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/xtensor-stack/xtensor/stable?filepath=notebooks%2Fxtensor.ipynb) [![Zulip](https://img.shields.io/badge/social_chat-zulip-blue.svg)](https://xtensor.zulipchat.com/#narrow/channel/539553-Ask-anything) +[![CodSpeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/xtensor-stack/xtensor?utm_source=badge) Multi-dimensional arrays with broadcasting and lazy computing. diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 9928eb155..0d0ce5766 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -16,17 +16,26 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(XTENSOR_INCLUDE_DIR ${xtensor_INCLUDE_DIRS}) endif () -message(STATUS "Forcing tests build type to Release") -set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) +if(CODSPEED_MODE AND NOT CODSPEED_MODE STREQUAL "off") + message(STATUS "CodSpeed mode enabled (${CODSPEED_MODE}) - using RelWithDebInfo build type") + set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE) +else() + message(STATUS "Forcing tests build type to Release") + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) +endif() include(CheckCXXCompilerFlag) string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") - CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported) - if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") + # Skip -march=native for CodSpeed simulation mode (valgrind does not + # support all native instruction sets) + if(NOT (CODSPEED_MODE STREQUAL "simulation")) + CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported) + if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") + endif() endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g -Wunused-parameter -Wextra -Wreorder") @@ -80,13 +89,14 @@ if(DOWNLOAD_GBENCHMARK OR GBENCHMARK_SRC_DIR) GIT_TAG main) FetchContent_Declare(googlebenchmark - GIT_REPOSITORY https://github.com/google/benchmark.git - GIT_TAG main) # need main for benchmark::benchmark + GIT_REPOSITORY https://github.com/CodSpeedHQ/codspeed-cpp.git + GIT_TAG main + SOURCE_SUBDIR google_benchmark) FetchContent_MakeAvailable( googletest googlebenchmark) - set(GBENCHMARK_INCLUDE_DIRS "${googlebenchmark_SOURCE_DIR}/include") + set(GBENCHMARK_INCLUDE_DIRS "${googlebenchmark_SOURCE_DIR}/google_benchmark/include") set(GBENCHMARK_LIBRARIES benchmark) else() find_package(benchmark REQUIRED)