mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
added benchmark
This commit is contained in:
@@ -6,6 +6,7 @@ include(CMakePackageConfigHelpers)
|
|||||||
|
|
||||||
|
|
||||||
option(OMATH_BUILD_TESTS "Build unit tests" ${PROJECT_IS_TOP_LEVEL})
|
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_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_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
|
||||||
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
|
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)
|
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_BUILD_TESTS)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (OMATH_BUILD_BENCHMARK)
|
||||||
|
add_subdirectory(benchmark)
|
||||||
|
endif ()
|
||||||
|
|
||||||
if (OMATH_BUILD_EXAMPLES)
|
if (OMATH_BUILD_EXAMPLES)
|
||||||
add_subdirectory(examples)
|
add_subdirectory(examples)
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -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})
|
||||||
31
benchmark/benchmark_mat.cpp
Normal file
31
benchmark/benchmark_mat.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 9/17/2025.
|
||||||
|
//
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <omath/omath.hpp>
|
||||||
|
#include <chrono>
|
||||||
|
#include <print>
|
||||||
|
|
||||||
|
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<std::chrono::microseconds>(end - start).count();
|
||||||
|
|
||||||
|
acum_time += static_cast<float>(time);
|
||||||
|
}
|
||||||
|
std::print("Elapsed: {}, \n\n\n", acum_time / iters, c);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user