diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml new file mode 100644 index 000000000..586973af3 --- /dev/null +++ b/.github/workflows/codspeed.yml @@ -0,0 +1,35 @@ +name: CodSpeed Benchmarks + +on: + push: + branches: + - "main" + paths-ignore: + - '**.md' + - 'docs/**' + pull_request: + # `workflow_dispatch` allows CodSpeed to trigger backtest + # performance analysis in order to generate initial data. + workflow_dispatch: + +permissions: + contents: read + +jobs: + benchmarks: + name: Run benchmarks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + - name: Build the benchmark target(s) + run: | + cmake -DCMAKE_BUILD_TYPE=Release -DADA_TESTING=OFF -DADA_DEVELOPMENT_CHECKS=OFF -DADA_USE_UNSAFE_STD_REGEX_PROVIDER=ON -DADA_BENCHMARKS=ON -DCODSPEED_MODE=simulation -G Ninja -B build + cmake --build build -j + env: + CXX: g++-12 + - name: Run the benchmarks + uses: CodSpeedHQ/action@v4 + with: + mode: simulation + run: cmake --build build --target run_all_benchmarks + diff --git a/CMakeLists.txt b/CMakeLists.txt index 565035b89..9ee0fea2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,15 +43,28 @@ if(ADA_TESTING OR ADA_BENCHMARKS OR ADA_TOOLS) endif() # We use Google Benchmark, but it does not build under several 32-bit systems. if(ADA_BENCHMARKS AND (CMAKE_SIZEOF_VOID_P EQUAL 8)) - CPMAddPackage( - NAME benchmark - GITHUB_REPOSITORY google/benchmark - VERSION 1.9.0 - OPTIONS "BENCHMARK_ENABLE_TESTING OFF" - "BENCHMARK_ENABLE_INSTALL OFF" - "BENCHMARK_ENABLE_WERROR OFF" - - ) + if(DEFINED CODSPEED_MODE) + message(STATUS "Using CodSpeed-instrumented Google Benchmark") + CPMAddPackage( + NAME benchmark + GITHUB_REPOSITORY CodSpeedHQ/codspeed-cpp + VERSION 2.0.0 + SOURCE_SUBDIR google_benchmark + OPTIONS "BENCHMARK_ENABLE_TESTING OFF" + "BENCHMARK_ENABLE_INSTALL OFF" + "BENCHMARK_ENABLE_WERROR OFF" + ) + else() + message(STATUS "Using standard Google Benchmark") + CPMAddPackage( + NAME benchmark + GITHUB_REPOSITORY google/benchmark + VERSION 1.9.0 + OPTIONS "BENCHMARK_ENABLE_TESTING OFF" + "BENCHMARK_ENABLE_INSTALL OFF" + "BENCHMARK_ENABLE_WERROR OFF" + ) + endif() endif() if (ADA_TESTING AND NOT EMSCRIPTEN) @@ -90,7 +103,7 @@ endif() add_library(ada::ada ALIAS ada) -if(ADA_TESTING) +if(ADA_TESTING OR ADA_USE_UNSAFE_STD_REGEX_PROVIDER) # IMPORTANT! # # We enable std_regex_provider for testing purposes diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index c54eb5d06..d9af9e637 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -64,6 +64,21 @@ target_link_libraries(percent_encode PRIVATE benchmark::benchmark) target_link_libraries(bench_search_params PRIVATE benchmark::benchmark) target_link_libraries(urlpattern PRIVATE benchmark::benchmark) +set(BENCHMARKS wpt_bench bench benchdata bbc_bench percent_encode bench_search_params urlpattern) + +add_custom_target(run_all_benchmarks + COMMAND ${CMAKE_COMMAND} -E echo "Running all benchmarks..." +) +foreach(benchmark IN LISTS BENCHMARKS) + add_custom_command( + TARGET run_all_benchmarks + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "Running ${benchmark}..." + COMMAND $ --benchmark_min_time=1s + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) +endforeach() + option(ADA_COMPETITION "Whether to install various competitors." OFF) # We only build url_whatwg if ICU is found, so we need to make