diff --git a/CMakeLists.txt b/CMakeLists.txt index e98cb97..2e1ec2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ include(CMakePackageConfigHelpers) option(OMATH_BUILD_TESTS "Build unit tests" ${PROJECT_IS_TOP_LEVEL}) +option(OMATH_BUILD_BENCHMARK "Build benchmarks" ${PROJECT_IS_TOP_LEVEL}) option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON) option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF) option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON) @@ -103,6 +104,10 @@ if (OMATH_BUILD_TESTS) target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_BUILD_TESTS) endif () +if (OMATH_BUILD_BENCHMARK) + add_subdirectory(benchmark) +endif () + if (OMATH_BUILD_EXAMPLES) add_subdirectory(examples) endif () diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index e69de29..8fd0f6d 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -0,0 +1,22 @@ +enable_testing() + +project(benchmark) + +include(GoogleTest) + +file(GLOB_RECURSE UNIT_TESTS_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") +add_executable(${PROJECT_NAME} ${UNIT_TESTS_SOURCES}) + +set_target_properties(benchmark PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" + UNITY_BUILD ON + UNITY_BUILD_BATCH_SIZE 20 + CXX_STANDARD 23 + CXX_STANDARD_REQUIRED ON) + + +target_link_libraries(${PROJECT_NAME} PRIVATE gtest gtest_main omath::omath) + +gtest_discover_tests(${PROJECT_NAME}) \ No newline at end of file diff --git a/benchmark/benchmark_mat.cpp b/benchmark/benchmark_mat.cpp new file mode 100644 index 0000000..dc23f56 --- /dev/null +++ b/benchmark/benchmark_mat.cpp @@ -0,0 +1,31 @@ +// +// Created by Vlad on 9/17/2025. +// +#include +#include +#include +#include + +using namespace omath; +TEST(MatPerformanceTest, Mutl) +{ + using mat_type = Mat<128, 128, float, MatStoreType::COLUMN_MAJOR>; + mat_type a; + mat_type b; + a.set(3.f); + b.set(7.f); + constexpr int iters = 1000; + float acum_time = 0.f; + mat_type c; + for (std::size_t i = 0 ; i < iters; i++) + { + const auto start = std::chrono::high_resolution_clock::now(); + c = a * b; + const auto end = std::chrono::high_resolution_clock::now(); + + const auto time = std::chrono::duration_cast(end - start).count(); + + acum_time += static_cast(time); + } + std::print("Elapsed: {}, \n\n\n", acum_time / iters, c); +} \ No newline at end of file