-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Catch2 v.3.5.0 changed output format (#247)
* create Catch2 v3 example * add test case for catch2 v3 * modify extract header regexp to work with v3
- Loading branch information
Showing
17 changed files
with
366 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Catch2 C++ Example | ||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
permissions: | ||
contents: write | ||
deployments: write | ||
|
||
jobs: | ||
benchmark: | ||
name: Run Catch2 C++ Benchmark Framework example (v2.x) | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build and run benchmarks with Catch2 | ||
run: | | ||
cd examples/catch2_v2 | ||
mkdir build && cd build | ||
cmake -DCMAKE_BUILD_TYPE=Release .. | ||
cmake --build . --config Release | ||
./Catch2_bench | tee ../benchmark_result.txt | ||
- name: Store benchmark result | ||
uses: benchmark-action/github-action-benchmark@v1 | ||
with: | ||
name: Catch2 Benchmark | ||
tool: 'catch2' | ||
output-file-path: examples/catch2_v2/benchmark_result.txt | ||
github-token: ${{ secrets.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: '@ktrz' | ||
|
||
- name: Store benchmark result - separate results repo | ||
uses: benchmark-action/github-action-benchmark@v1 | ||
with: | ||
name: Catch2 Benchmark | ||
tool: 'catch2' | ||
output-file-path: examples/catch2_v2/benchmark_result.txt | ||
github-token: ${{ secrets.BENCHMARK_ACTION_BOT_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: '@ktrz' | ||
gh-repository: 'github.com/benchmark-action/github-action-benchmark-results' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.13.10) | ||
|
||
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 | ||
$<$<CXX_COMPILER_ID:MSVC>:/DCATCH_CONFIG_ENABLE_BENCHMARKING> | ||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-DCATCH_CONFIG_ENABLE_BENCHMARKING> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
C++ example for benchmarking with [Catch2 Framework][tool] | ||
==================================================================== | ||
|
||
- [Workflow for this example](../../.github/workflows/catch2.yml) | ||
- [Action log of this example](https://github.com/benchmark-action/github-action-benchmark/actions?query=workflow%3A%22Catch2+C%2B%2B+Example%22) | ||
- [Benchmark results on GitHub pages](https://benchmark-action.github.io/github-action-benchmark/dev/bench/) | ||
|
||
This directory shows how to use [`github-action-benchmark`][action] with [Catch2 Framework][tool]. | ||
|
||
|
||
|
||
## Run benchmarks | ||
|
||
Official documentation for usage of Catch2 Framework can be found in its repository: | ||
|
||
https://github.com/catchorg/Catch2 | ||
|
||
Since Catch2 is a header-only test framework, you don't need to build it in advance. | ||
Download and put the headers in your `include` directory and write your benchmarks. | ||
|
||
```cpp | ||
#define CATCH_CONFIG_MAIN | ||
#include <catch2/catch.hpp> | ||
|
||
TEST_CASE("Fibonacci") { | ||
// now let's benchmark: | ||
BENCHMARK("Some benchmark") { | ||
// Your benchmark goes here | ||
}; | ||
} | ||
``` | ||
Build the source with C++ compiler and run the built executable to get the benchmark output. | ||
Ensure to use `console` reporter for this. `xml` reporter may be supported in the future. | ||
## Process benchmark results | ||
Store the benchmark results with step using the action. Please set `catch2` to `tool` input. | ||
```yaml | ||
- name: Store benchmark result | ||
uses: benchmark-action/github-action-benchmark@v1 | ||
with: | ||
tool: 'catch2' | ||
output-file-path: benchmark_result.json | ||
``` | ||
|
||
Please read ['How to use' section](https://github.com/benchmark-action/github-action-benchmark#how-to-use) for common usage. | ||
|
||
|
||
|
||
## Run this example | ||
|
||
To try this example, please use [cmake](./CMakeLists.txt) and `clang++`. | ||
|
||
```sh | ||
$ mkdir build | ||
$ cd build | ||
$ cmake -DCMAKE_BUILD_TYPE=Release .. | ||
$ cmake --build . --config Release | ||
``` | ||
|
||
This will create `Catch2_bench` executable. The results are output to stdout. | ||
|
||
[tool]: https://github.com/catchorg/Catch2 | ||
[action]: https://github.com/benchmark-action/github-action-benchmark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "fib.hpp" | ||
#define CATCH_CONFIG_MAIN | ||
#include <catch2/catch.hpp> | ||
|
||
TEST_CASE("Fibonacci") { | ||
|
||
// now let's benchmark: | ||
BENCHMARK("Fibonacci 10") { return fib(10); }; | ||
|
||
BENCHMARK("Fibonacci 20") { return fib(20); }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.