Skip to content

Commit 1251271

Browse files
committed
testing Continous Benchmarking
1 parent a5ca86a commit 1251271

File tree

5 files changed

+107
-2
lines changed

5 files changed

+107
-2
lines changed

.github/workflows/Benchmark.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: MaCh3 Benchmark
2+
3+
on:
4+
push:
5+
branches:
6+
- [feature_benchmark, main]
7+
8+
permissions:
9+
# Required permissions for GitHub Pages deployment and content updates
10+
deployments: write
11+
contents: write
12+
13+
jobs:
14+
benchmark:
15+
name: Performance regression check
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Get MaCh3 Validations
19+
run: |
20+
cd /opt/
21+
# Clone the MaCh3Tutorial repository with the current branch
22+
git clone --branch "${{ github.head_ref }}" https://github.com/mach3-software/MaCh3Tutorial.git MaCh3Validations
23+
cd MaCh3Validations
24+
mkdir build
25+
cd build
26+
# Configure the project with benchmark support enabled
27+
cmake ../ -MaCh3Tutorial_Benchmark_ENABLED=TRUE
28+
29+
- name: Build MaCh3 Validations
30+
run: |
31+
cd /opt/MaCh3Validations/build
32+
make -j4 install # Build and install the project
33+
34+
- name: Run benchmark
35+
run: |
36+
# Source environment setup scripts
37+
source /opt/MaCh3Validations/build/bin/setup.MaCh3.sh
38+
source /opt/MaCh3Validations/build/bin/setup.MaCh3Tutorial.sh
39+
source /opt/MaCh3Validations/build/bin/setup.NuOscillator.sh
40+
cd /opt/MaCh3Validations/build/CIValidations
41+
# Run the benchmark and store the output in a file
42+
./Benchmark/MaCh3Benchmark | tee output.txt
43+
44+
- name: Store benchmark result
45+
uses: benchmark-action/github-action-benchmark@v1
46+
with:
47+
tool: 'catch2' # Specify that the benchmark tool is Catch2
48+
github-token: ${{ secrets.GITHUB_TOKEN }} # Use GitHub token for authentication
49+
output-file-path: output.txt # Path to the benchmark output file
50+
alert-threshold: 200% # Alert threshold for performance degradation
51+
gh-pages-branch: gh-pages # Branch to store benchmark results
52+
gh-repository: mach3-software/MaCh3Tutorial # Repository for benchmark results
53+
summary-always: true # Always show summary in job logs
54+
fail-on-alert: false # Do not fail the workflow on alert
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
foreach(TEST
2+
MaCh3Benchmark
3+
)
4+
5+
add_executable(${TEST} ${TEST}.cpp)
6+
target_link_libraries(${TEST} PRIVATE Catch2::Catch2WithMain MaCh3::All MaCh3Tutorial::samplePDFTutorial)
7+
catch_discover_tests(${TEST})
8+
endforeach()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// MaCh3 spline includes
2+
#include "mcmc/MaCh3Factory.h"
3+
#include "samplePDF/samplePDFTutorial.h"
4+
5+
#include "catch2/catch_test_macros.hpp"
6+
#include "catch2/benchmark/catch_benchmark.hpp"
7+
8+
TEST_CASE("Benchmark MaCh3") {
9+
// Initialise manger responsible for config handling
10+
auto FitManager = std::make_unique<manager>("Inputs/FitterConfig.yaml");
11+
12+
// Initialise covariance class reasonable for Systematics
13+
covarianceXsec* xsec = MaCh3CovarianceFactory(FitManager.get(), "Xsec");
14+
covarianceOsc* osc = MaCh3CovarianceFactory<covarianceOsc>(FitManager.get(), "Osc");
15+
16+
// Initialise samplePDF
17+
auto SampleConfig = FitManager->raw()["General"]["TutorialSamples"].as<std::vector<std::string>>();
18+
auto mySamples = MaCh3SamplePDFFactory<samplePDFTutorial>(SampleConfig, xsec, osc);
19+
20+
// Create MCMC Class
21+
std::unique_ptr<FitterBase> MaCh3Fitter = MaCh3FitterFactory(FitManager.get());
22+
// Add covariance to MCM
23+
MaCh3Fitter->addSystObj(xsec);
24+
MaCh3Fitter->addSystObj(osc);
25+
for (size_t i = 0; i < SampleConfig.size(); ++i) {
26+
MaCh3Fitter->addSamplePDF(mySamples[i]);
27+
}
28+
// Benchmark
29+
BENCHMARK("MaCh3Fitter::DragRace") {
30+
MaCh3Fitter->DragRace(1);
31+
};
32+
33+
delete xsec;
34+
delete osc;
35+
for (size_t i = 0; i < SampleConfig.size(); ++i) {
36+
delete mySamples[i];
37+
}
38+
}

CIValidations/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ install(DIRECTORY
3939
if(MaCh3Tutorial_UNITTESTS_ENABLED)
4040
add_subdirectory(UnitTests)
4141
endif()
42+
43+
if(MaCh3Tutorial_Benchmark_ENABLED)
44+
add_subdirectory(Benchmark)
45+
endif()

cmake/Modules/CIValidations.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
option(MaCh3Tutorial_UNITTESTS_ENABLED "Whether to build MaCh3 Unit Tests" OFF)
2-
option(MaCh3Tutorial_Coverage_ENABLED "Whether to build MaCh3 Coverage " OFF)
2+
option(MaCh3Tutorial_Coverage_ENABLED "Whether to build MaCh3 Coverage" OFF)
3+
option(MaCh3Tutorial_Benchmark_ENABLED "Enable benchmarking" ON) # WARNING FIXME
34

45
CPMAddPackage(
56
NAME NuMCMCTools
@@ -14,7 +15,7 @@ install(DIRECTORY
1415
DESTINATION ${CMAKE_BINARY_DIR}/NuMCMCTools)
1516

1617
############################ Catch2/CTest ####################################
17-
if(MaCh3Tutorial_UNITTESTS_ENABLED)
18+
if(MaCh3Tutorial_UNITTESTS_ENABLED OR MaCh3Tutorial_Benchmark_ENABLED)
1819
find_package(Catch2 QUIET)
1920
if(NOT Catch2_FOUND)
2021
CPMAddPackage("gh:catchorg/Catch2@3.5.2")

0 commit comments

Comments
 (0)