mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
added benchmark submodule
This commit is contained in:
5
.gitmodules
vendored
5
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
||||
[submodule "extlibs/googletest"]
|
||||
path = extlibs/googletest
|
||||
url = https://github.com/google/googletest.git
|
||||
url = https://github.com/google/googletest.git
|
||||
[submodule "extlibs/benchmark"]
|
||||
path = extlibs/benchmark
|
||||
url = https://github.com/google/benchmark.git
|
||||
|
||||
@@ -20,6 +20,7 @@ option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY fo
|
||||
message(STATUS "[${PROJECT_NAME}]: Building on ${CMAKE_HOST_SYSTEM_NAME}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Warnings as errors ${OMATH_THREAT_WARNING_AS_ERROR}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Build unit tests ${OMATH_BUILD_TESTS}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Build benchmark ${OMATH_BUILD_BENCHMARK}")
|
||||
message(STATUS "[${PROJECT_NAME}]: As dynamic library ${OMATH_BUILD_AS_SHARED_LIBRARY}")
|
||||
message(STATUS "[${PROJECT_NAME}]: Static C++ runtime ${OMATH_STATIC_MSVC_RUNTIME_LIBRARY}")
|
||||
message(STATUS "[${PROJECT_NAME}]: CMake unity build ${OMATH_USE_UNITY_BUILD}")
|
||||
@@ -97,9 +98,11 @@ endif ()
|
||||
|
||||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)
|
||||
|
||||
if (OMATH_BUILD_TESTS OR OMATH_BUILD_BENCHMARK)
|
||||
add_subdirectory(extlibs)
|
||||
endif ()
|
||||
|
||||
if (OMATH_BUILD_TESTS)
|
||||
add_subdirectory(extlibs)
|
||||
add_subdirectory(tests)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_BUILD_TESTS)
|
||||
endif ()
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
enable_testing()
|
||||
project(omath_benchmark)
|
||||
|
||||
project(benchmark)
|
||||
|
||||
include(GoogleTest)
|
||||
file(GLOB_RECURSE OMATH_BENCHMARK_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
add_executable(${PROJECT_NAME} ${OMATH_BENCHMARK_SOURCES})
|
||||
|
||||
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
|
||||
set_target_properties(${PROJECT_NAME} 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}"
|
||||
@@ -17,6 +14,4 @@ set_target_properties(benchmark PROPERTIES
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE gtest gtest_main omath::omath)
|
||||
|
||||
gtest_discover_tests(${PROJECT_NAME})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE benchmark::benchmark omath)
|
||||
@@ -1,31 +1,28 @@
|
||||
//
|
||||
// Created by Vlad on 9/17/2025.
|
||||
//
|
||||
#include <gtest/gtest.h>
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
#include <omath/omath.hpp>
|
||||
#include <chrono>
|
||||
#include <print>
|
||||
|
||||
using namespace omath;
|
||||
TEST(MatPerformanceTest, Mutl)
|
||||
|
||||
static void BM_MatMutiplication(benchmark::State& state)
|
||||
{
|
||||
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++)
|
||||
|
||||
|
||||
for (auto _ : state)
|
||||
{
|
||||
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::ignore = a * b;
|
||||
}
|
||||
std::print("Elapsed: {}, \n\n\n", acum_time / iters, c);
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(BM_MatMutiplication);
|
||||
BENCHMARK_MAIN();
|
||||
@@ -1 +1,2 @@
|
||||
add_subdirectory(googletest)
|
||||
add_subdirectory(googletest)
|
||||
add_subdirectory(benchmark)
|
||||
1
extlibs/benchmark
Submodule
1
extlibs/benchmark
Submodule
Submodule extlibs/benchmark added at 2948b6a2e6
Reference in New Issue
Block a user