Skip to content

Commit

Permalink
Added catch2 example
Browse files Browse the repository at this point in the history
  • Loading branch information
bernedom committed Jan 12, 2020
1 parent 1b486a8 commit b5bf27a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/catch2.yml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions examples/catch2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
26 changes: 26 additions & 0 deletions examples/catch2/CMakeLists.txt
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.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
$<$<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>
)
11 changes: 11 additions & 0 deletions examples/catch2/catch2_bench.cpp
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 20") { return fib(20); };

BENCHMARK("Fibonacci 25") { return fib(25); };
}
11 changes: 11 additions & 0 deletions examples/catch2/fib.hpp
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
1 change: 1 addition & 0 deletions src/default_index_html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const DEFAULT_INDEX_HTML = String.raw`<!DOCTYPE html>
benchmarkjs: '#f1e05a',
pytest: '#3572a5',
googlecpp: '#f34b7d',
catch2: '#f34b7d',
_: '#333333'
};
Expand Down

0 comments on commit b5bf27a

Please sign in to comment.