mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-07 13:10:42 +02:00
added benchmark to time generalize calculate_eta - twice as long so will keep specific version for 2x2 and 3x3 clusters
This commit is contained in:
parent
ed9ef7c600
commit
7e5f91c6ec
@ -81,14 +81,14 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|||||||
|
|
||||||
if(AARE_FETCH_LMFIT)
|
if(AARE_FETCH_LMFIT)
|
||||||
#TODO! Should we fetch lmfit from the web or inlcude a tar.gz in the repo?
|
#TODO! Should we fetch lmfit from the web or inlcude a tar.gz in the repo?
|
||||||
set(lmfit_patch git apply ${CMAKE_CURRENT_SOURCE_DIR}/patches/lmfit.patch)
|
#set(lmfit_patch git apply ${CMAKE_CURRENT_SOURCE_DIR}/patches/lmfit.patch)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
lmfit
|
lmfit
|
||||||
GIT_REPOSITORY https://jugit.fz-juelich.de/mlz/lmfit.git
|
GIT_REPOSITORY https://jugit.fz-juelich.de/mlz/lmfit.git
|
||||||
GIT_TAG main
|
GIT_TAG main
|
||||||
PATCH_COMMAND ${lmfit_patch}
|
#PATCH_COMMAND ${lmfit_patch}
|
||||||
UPDATE_DISCONNECTED 1
|
#UPDATE_DISCONNECTED 1
|
||||||
EXCLUDE_FROM_ALL 1
|
#EXCLUDE_FROM_ALL 1
|
||||||
)
|
)
|
||||||
#Disable what we don't need from lmfit
|
#Disable what we don't need from lmfit
|
||||||
set(BUILD_TESTING OFF CACHE BOOL "")
|
set(BUILD_TESTING OFF CACHE BOOL "")
|
||||||
@ -359,7 +359,7 @@ set(SourceFiles
|
|||||||
add_library(aare_core STATIC ${SourceFiles})
|
add_library(aare_core STATIC ${SourceFiles})
|
||||||
target_include_directories(aare_core PUBLIC
|
target_include_directories(aare_core PUBLIC
|
||||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
||||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" PRIVATE ${lmfit_SOURCE_DIR}/lib
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,11 +1,27 @@
|
|||||||
find_package(benchmark REQUIRED)
|
|
||||||
|
|
||||||
add_executable(ndarray_benchmark ndarray_benchmark.cpp)
|
include(FetchContent)
|
||||||
|
|
||||||
target_link_libraries(ndarray_benchmark benchmark::benchmark aare_core aare_compiler_flags)
|
|
||||||
# target_link_libraries(tests PRIVATE aare_core aare_compiler_flags)
|
|
||||||
|
|
||||||
set_target_properties(ndarray_benchmark PROPERTIES
|
FetchContent_Declare(
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
|
benchmark
|
||||||
# OUTPUT_NAME run_tests
|
GIT_REPOSITORY https://github.com/google/benchmark.git
|
||||||
|
GIT_TAG v1.8.3 # Change to the latest version if needed
|
||||||
|
)
|
||||||
|
|
||||||
|
# Ensure Google Benchmark is built correctly
|
||||||
|
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
|
||||||
|
|
||||||
|
FetchContent_MakeAvailable(benchmark)
|
||||||
|
|
||||||
|
add_executable(benchmarks)
|
||||||
|
|
||||||
|
target_sources(benchmarks PRIVATE ndarray_benchmark.cpp calculateeta_benchmark.cpp)
|
||||||
|
|
||||||
|
# Link Google Benchmark and other necessary libraries
|
||||||
|
target_link_libraries(benchmarks PRIVATE benchmark::benchmark aare_core aare_compiler_flags)
|
||||||
|
|
||||||
|
# Set output properties
|
||||||
|
set_target_properties(benchmarks PROPERTIES
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
|
OUTPUT_NAME run_benchmarks
|
||||||
)
|
)
|
66
benchmarks/calculateeta_benchmark.cpp
Normal file
66
benchmarks/calculateeta_benchmark.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include "aare/ClusterFile.hpp"
|
||||||
|
#include <benchmark/benchmark.h>
|
||||||
|
|
||||||
|
using namespace aare;
|
||||||
|
|
||||||
|
class ClusterFixture : public benchmark::Fixture {
|
||||||
|
public:
|
||||||
|
Cluster<int, 2, 2> cluster_2x2{};
|
||||||
|
Cluster<int, 3, 3> cluster_3x3{};
|
||||||
|
|
||||||
|
void SetUp(::benchmark::State &state) {
|
||||||
|
int temp_data[4] = {1, 2, 3, 1};
|
||||||
|
std::copy(std::begin(temp_data), std::end(temp_data),
|
||||||
|
std::begin(cluster_2x2.data));
|
||||||
|
|
||||||
|
cluster_2x2.x = 0;
|
||||||
|
cluster_2x2.y = 0;
|
||||||
|
|
||||||
|
int temp_data2[9] = {1, 2, 3, 1, 3, 4, 5, 1, 20};
|
||||||
|
std::copy(std::begin(temp_data2), std::end(temp_data2),
|
||||||
|
std::begin(cluster_3x3.data));
|
||||||
|
|
||||||
|
cluster_3x3.x = 0;
|
||||||
|
cluster_3x3.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// void TearDown(::benchmark::State& state) {
|
||||||
|
// }
|
||||||
|
};
|
||||||
|
|
||||||
|
BENCHMARK_F(ClusterFixture, Calculate2x2Eta)(benchmark::State &st) {
|
||||||
|
for (auto _ : st) {
|
||||||
|
// This code gets timed
|
||||||
|
Eta2 eta = calculate_eta2(cluster_2x2);
|
||||||
|
benchmark::DoNotOptimize(eta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// almost takes double the time
|
||||||
|
BENCHMARK_F(ClusterFixture,
|
||||||
|
CalculateGeneralEtaFor2x2Cluster)(benchmark::State &st) {
|
||||||
|
for (auto _ : st) {
|
||||||
|
// This code gets timed
|
||||||
|
Eta2 eta = calculate_eta2<int, 2, 2>(cluster_2x2);
|
||||||
|
benchmark::DoNotOptimize(eta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK_F(ClusterFixture, Calculate3x3Eta)(benchmark::State &st) {
|
||||||
|
for (auto _ : st) {
|
||||||
|
// This code gets timed
|
||||||
|
Eta2 eta = calculate_eta2(cluster_3x3);
|
||||||
|
benchmark::DoNotOptimize(eta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// almost takes double the time
|
||||||
|
BENCHMARK_F(ClusterFixture,
|
||||||
|
CalculateGeneralEtaFor3x3Cluster)(benchmark::State &st) {
|
||||||
|
for (auto _ : st) {
|
||||||
|
// This code gets timed
|
||||||
|
Eta2 eta = calculate_eta2<int, 3, 3>(cluster_3x3);
|
||||||
|
benchmark::DoNotOptimize(eta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// BENCHMARK_MAIN();
|
@ -445,7 +445,7 @@ Eta2 calculate_eta2(
|
|||||||
* @brief Calculate the eta2 values for a 3x3 cluster and return them in a Eta2
|
* @brief Calculate the eta2 values for a 3x3 cluster and return them in a Eta2
|
||||||
* struct containing etay, etax and the corner of the cluster.
|
* struct containing etay, etax and the corner of the cluster.
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
template <typename T> Eta2 calculate_eta2(const Cluster<T, 3, 3> &cl) {
|
template <typename T> Eta2 calculate_eta2(const Cluster<T, 3, 3> &cl) {
|
||||||
Eta2 eta{};
|
Eta2 eta{};
|
||||||
|
|
||||||
@ -489,9 +489,7 @@ template <typename T> Eta2 calculate_eta2(const Cluster<T, 3, 3> &cl) {
|
|||||||
}
|
}
|
||||||
return eta;
|
return eta;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
template <typename T> Eta2 calculate_eta2(const Cluster<T, 2, 2> &cl) {
|
template <typename T> Eta2 calculate_eta2(const Cluster<T, 2, 2> &cl) {
|
||||||
Eta2 eta{};
|
Eta2 eta{};
|
||||||
|
|
||||||
@ -501,7 +499,6 @@ template <typename T> Eta2 calculate_eta2(const Cluster<T, 2, 2> &cl) {
|
|||||||
eta.c = cBottomLeft; // TODO! This is not correct, but need to put something
|
eta.c = cBottomLeft; // TODO! This is not correct, but need to put something
|
||||||
return eta;
|
return eta;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// calculates Eta3 for 3x3 cluster based on code from analyze_cluster
|
// calculates Eta3 for 3x3 cluster based on code from analyze_cluster
|
||||||
// TODO only supported for 3x3 Clusters
|
// TODO only supported for 3x3 Clusters
|
||||||
|
Loading…
x
Reference in New Issue
Block a user