diff --git a/.github/workflows/catch2.yml b/.github/workflows/catch2.yml new file mode 100644 index 000000000..4b0b6f33f --- /dev/null +++ b/.github/workflows/catch2.yml @@ -0,0 +1,29 @@ +name: Catch2 C++ Example +on: push + +jobs: + benchmark: + name: Run C++ benchmark example + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: | + cd examples/catch2 + mkdir build && cd build + cmake -DCMAKE_BUILD_TYPE=Release .. + cmake --build . --config Release + ./Catch2_bench > ../benchmark_result.txt + - name: Store benchmark result + uses: ./ + with: + name: Catch2 Benchmark + tool: "catch2" + output-file-path: examples/catch2/benchmark_result.txt + # Use personal access token instead of GITHUB_TOKEN due to https://github.community/t5/GitHub-Actions/Github-action-not-triggering-gh-pages-upon-push/td-p/26869/highlight/false + github-token: ${{ secrets.PERSONAL_GITHUB_TOKEN }} + auto-push: true + # Show alert with commit comment on detecting possible performance regression + alert-threshold: "200%" + comment-on-alert: true + fail-on-alert: true + alert-comment-cc-users: "@bernedom" diff --git a/examples/catch2/.gitignore b/examples/catch2/.gitignore new file mode 100644 index 000000000..d16386367 --- /dev/null +++ b/examples/catch2/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/examples/catch2/CMakeLists.txt b/examples/catch2/CMakeLists.txt new file mode 100644 index 000000000..6ed2214c2 --- /dev/null +++ b/examples/catch2/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.12) +project("Catch2_bench") + +include(FetchContent) + +FetchContent_Declare( + catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v2.11.0) + +FetchContent_GetProperties(catch2) +if(NOT catch2_POPULATED) + FetchContent_Populate(catch2) + add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR}) +endif() + +add_executable(${PROJECT_NAME}) +target_sources(${PROJECT_NAME} PRIVATE catch2_bench.cpp) +target_link_libraries(${PROJECT_NAME} Catch2::Catch2) + +target_compile_options( + ${PROJECT_NAME} + PRIVATE + $<$:/DCATCH_CONFIG_ENABLE_BENCHMARKING> + $<$,$,$>:-DCATCH_CONFIG_ENABLE_BENCHMARKING> +) diff --git a/examples/catch2/catch2_bench.cpp b/examples/catch2/catch2_bench.cpp new file mode 100644 index 000000000..cab08bf83 --- /dev/null +++ b/examples/catch2/catch2_bench.cpp @@ -0,0 +1,11 @@ +#include "fib.hpp" +#define CATCH_CONFIG_MAIN +#include + +TEST_CASE("Fibonacci") { + + // now let's benchmark: + BENCHMARK("Fibonacci 20") { return fib(20); }; + + BENCHMARK("Fibonacci 25") { return fib(25); }; +} \ No newline at end of file diff --git a/examples/catch2/fib.hpp b/examples/catch2/fib.hpp new file mode 100644 index 000000000..559e886c8 --- /dev/null +++ b/examples/catch2/fib.hpp @@ -0,0 +1,11 @@ +#if !defined FIB_HPP_INCLUDED +#define FIB_HPP_INCLUDED + +int fib(int const i) { + if (i <= 1) { + return 1; + } + return fib(i - 2) + fib(i - 1); +} + +#endif // FIB_HPP_INCLUDED diff --git a/src/default_index_html.ts b/src/default_index_html.ts index 94e98ac6e..e65c50223 100644 --- a/src/default_index_html.ts +++ b/src/default_index_html.ts @@ -116,6 +116,7 @@ export const DEFAULT_INDEX_HTML = String.raw` benchmarkjs: '#f1e05a', pytest: '#3572a5', googlecpp: '#f34b7d', + catch2: '#f34b7d', _: '#333333' };