mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-13 19:18:01 +07:00
add google benchmark for the future
This commit is contained in:
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -4,3 +4,9 @@
|
||||
[submodule "develop/vendors/fmt"]
|
||||
path = develop/vendors/fmt
|
||||
url = https://github.com/fmtlib/fmt
|
||||
[submodule "develop/vendors/gbench"]
|
||||
path = develop/vendors/gbench
|
||||
url = https://github.com/google/benchmark
|
||||
[submodule "develop/vendors/vmath.hpp"]
|
||||
path = develop/vendors/vmath.hpp
|
||||
url = https://github.com/BlackMATov/vmath.hpp
|
||||
|
||||
@@ -16,6 +16,7 @@ include(SetupTargets)
|
||||
|
||||
add_subdirectory(manuals)
|
||||
add_subdirectory(singles)
|
||||
add_subdirectory(unbench)
|
||||
add_subdirectory(untests)
|
||||
add_subdirectory(vendors)
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
add_library(${PROJECT_NAME}.setup_targets INTERFACE)
|
||||
add_library(${PROJECT_NAME}::setup_targets ALIAS ${PROJECT_NAME}.setup_targets)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE
|
||||
meta.hpp.vendors::doctest
|
||||
meta.hpp.vendors::fmt)
|
||||
|
||||
target_compile_options(${PROJECT_NAME}.setup_targets INTERFACE
|
||||
$<$<CXX_COMPILER_ID:MSVC>:
|
||||
/WX /W4>
|
||||
@@ -15,6 +11,7 @@ target_compile_options(${PROJECT_NAME}.setup_targets INTERFACE
|
||||
-Wno-c++98-compat
|
||||
-Wno-c++98-compat-pedantic
|
||||
-Wno-exit-time-destructors
|
||||
-Wno-global-constructors
|
||||
-Wno-padded
|
||||
-Wno-unneeded-internal-declaration
|
||||
-Wno-unused-macros
|
||||
@@ -23,26 +20,13 @@ target_compile_options(${PROJECT_NAME}.setup_targets INTERFACE
|
||||
-Wno-zero-as-null-pointer-constant
|
||||
>)
|
||||
|
||||
if(BUILD_WITH_COVERAGE)
|
||||
target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE
|
||||
meta.hpp::enable_gcov)
|
||||
endif()
|
||||
|
||||
if(BUILD_WITH_SANITIZERS)
|
||||
target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE
|
||||
target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE
|
||||
$<$<BOOL:${BUILD_WITH_COVERAGE}>:
|
||||
meta.hpp::enable_gcov>
|
||||
$<$<BOOL:${BUILD_WITH_SANITIZERS}>:
|
||||
meta.hpp::enable_asan
|
||||
meta.hpp::enable_ubsan)
|
||||
endif()
|
||||
|
||||
if(BUILD_WITH_NO_EXCEPTIONS)
|
||||
target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE
|
||||
meta.hpp::disable_exceptions)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME}.setup_targets INTERFACE
|
||||
DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS)
|
||||
endif()
|
||||
|
||||
if(BUILD_WITH_NO_RTTI)
|
||||
target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE
|
||||
meta.hpp::disable_rtti)
|
||||
endif()
|
||||
meta.hpp::enable_ubsan>
|
||||
$<$<BOOL:${BUILD_WITH_NO_EXCEPTIONS}>:
|
||||
meta.hpp::disable_exceptions>
|
||||
$<$<BOOL:${BUILD_WITH_NO_RTTI}>:
|
||||
meta.hpp::disable_rtti>)
|
||||
|
||||
@@ -8,11 +8,15 @@ add_executable(${PROJECT_NAME}.singles ${MANUALS_SOURCES})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
meta.hpp::meta.hpp
|
||||
meta.hpp::setup_targets)
|
||||
meta.hpp::setup_targets
|
||||
meta.hpp.vendors::doctest
|
||||
meta.hpp.vendors::fmt)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}.singles PRIVATE
|
||||
meta.hpp::singles
|
||||
meta.hpp::setup_targets)
|
||||
meta.hpp::setup_targets
|
||||
meta.hpp.vendors::doctest
|
||||
meta.hpp.vendors::fmt)
|
||||
|
||||
add_test(${PROJECT_NAME} ${PROJECT_NAME})
|
||||
add_test(${PROJECT_NAME} ${PROJECT_NAME}.singles)
|
||||
|
||||
22
develop/unbench/CMakeLists.txt
Normal file
22
develop/unbench/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
project(meta.hpp.unbench)
|
||||
|
||||
file(GLOB_RECURSE UNBENCH_SOURCES CONFIGURE_DEPENDS "*.cpp" "*.hpp")
|
||||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${UNBENCH_SOURCES})
|
||||
|
||||
add_executable(${PROJECT_NAME} ${UNBENCH_SOURCES})
|
||||
add_executable(${PROJECT_NAME}.singles ${UNBENCH_SOURCES})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
meta.hpp::meta.hpp
|
||||
meta.hpp::setup_targets
|
||||
meta.hpp.vendors::gbench
|
||||
meta.hpp.vendors::vmath.hpp)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}.singles PRIVATE
|
||||
meta.hpp::singles
|
||||
meta.hpp::setup_targets
|
||||
meta.hpp.vendors::gbench
|
||||
meta.hpp.vendors::vmath.hpp)
|
||||
|
||||
add_test(${PROJECT_NAME} ${PROJECT_NAME})
|
||||
add_test(${PROJECT_NAME} ${PROJECT_NAME}.singles)
|
||||
61
develop/unbench/invoke_with_args_bench.cpp
Normal file
61
develop/unbench/invoke_with_args_bench.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include <meta.hpp/meta_all.hpp>
|
||||
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <vmath.hpp/vmath_all.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace meta = meta_hpp;
|
||||
namespace vmath = vmath_hpp;
|
||||
|
||||
struct clazz {
|
||||
static float static_function(float angle, const vmath::fvec3& axis) {
|
||||
return vmath::determinant(vmath::inverse(vmath::rotate4(angle, axis)));
|
||||
}
|
||||
};
|
||||
|
||||
const float angle{0.2f};
|
||||
const meta::uvalue angle_v{angle};
|
||||
|
||||
const vmath::fvec3 axis{1.f, 0.f, 0.f};
|
||||
const meta::uvalue axis_v{axis};
|
||||
|
||||
const meta::function dynamic_function{[](){
|
||||
meta::class_<clazz>().function_("static_function", &clazz::static_function);
|
||||
return meta::resolve_type<clazz>().get_function("static_function");
|
||||
}()};
|
||||
|
||||
void invoke_with_args_native(benchmark::State &state) {
|
||||
for ( auto _ : state ) {
|
||||
const auto r{clazz::static_function(angle, axis)};
|
||||
benchmark::DoNotOptimize(r);
|
||||
benchmark::ClobberMemory();
|
||||
}
|
||||
}
|
||||
|
||||
void invoke_with_args_dynamic1(benchmark::State &state) {
|
||||
for ( auto _ : state ) {
|
||||
const auto r{meta::invoke(&clazz::static_function, angle, axis)};
|
||||
benchmark::DoNotOptimize(r);
|
||||
benchmark::ClobberMemory();
|
||||
}
|
||||
}
|
||||
|
||||
void invoke_with_args_dynamic2(benchmark::State &state) {
|
||||
for ( auto _ : state ) {
|
||||
const auto r{meta::invoke(dynamic_function, angle_v, axis_v)};
|
||||
benchmark::DoNotOptimize(r);
|
||||
benchmark::ClobberMemory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(invoke_with_args_native);
|
||||
BENCHMARK(invoke_with_args_dynamic1);
|
||||
BENCHMARK(invoke_with_args_dynamic2);
|
||||
55
develop/unbench/invoke_without_args_bench.cpp
Normal file
55
develop/unbench/invoke_without_args_bench.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include <meta.hpp/meta_all.hpp>
|
||||
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <vmath.hpp/vmath_all.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace meta = meta_hpp;
|
||||
namespace vmath = vmath_hpp;
|
||||
|
||||
struct clazz {
|
||||
static float static_function() {
|
||||
return vmath::determinant(vmath::inverse(vmath::fmat4{}));
|
||||
}
|
||||
};
|
||||
|
||||
const meta::function dynamic_function{[](){
|
||||
meta::class_<clazz>().function_("static_function", &clazz::static_function);
|
||||
return meta::resolve_type<clazz>().get_function("static_function");
|
||||
}()};
|
||||
|
||||
void invoke_without_args_native(benchmark::State &state) {
|
||||
for ( auto _ : state ) {
|
||||
const auto r{clazz::static_function()};
|
||||
benchmark::DoNotOptimize(r);
|
||||
benchmark::ClobberMemory();
|
||||
}
|
||||
}
|
||||
|
||||
void invoke_without_args_dynamic1(benchmark::State &state) {
|
||||
for ( auto _ : state ) {
|
||||
const auto r{meta::invoke(&clazz::static_function)};
|
||||
benchmark::DoNotOptimize(r);
|
||||
benchmark::ClobberMemory();
|
||||
}
|
||||
}
|
||||
|
||||
void invoke_without_args_dynamic2(benchmark::State &state) {
|
||||
for ( auto _ : state ) {
|
||||
const auto r{meta::invoke(dynamic_function)};
|
||||
benchmark::DoNotOptimize(r);
|
||||
benchmark::ClobberMemory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(invoke_without_args_native);
|
||||
BENCHMARK(invoke_without_args_dynamic1);
|
||||
BENCHMARK(invoke_without_args_dynamic2);
|
||||
@@ -8,11 +8,13 @@ add_executable(${PROJECT_NAME}.singles ${UNTESTS_SOURCES})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
meta.hpp::meta.hpp
|
||||
meta.hpp::setup_targets)
|
||||
meta.hpp::setup_targets
|
||||
meta.hpp.vendors::doctest)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}.singles PRIVATE
|
||||
meta.hpp::singles
|
||||
meta.hpp::setup_targets)
|
||||
meta.hpp::setup_targets
|
||||
meta.hpp.vendors::doctest)
|
||||
|
||||
add_test(${PROJECT_NAME} ${PROJECT_NAME})
|
||||
add_test(${PROJECT_NAME} ${PROJECT_NAME}.singles)
|
||||
|
||||
38
develop/vendors/CMakeLists.txt
vendored
38
develop/vendors/CMakeLists.txt
vendored
@@ -14,8 +14,12 @@ target_include_directories(${PROJECT_NAME}.doctest SYSTEM
|
||||
PUBLIC doctest)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME}.doctest
|
||||
PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
INTERFACE DOCTEST_CONFIG_USE_STD_HEADERS)
|
||||
PRIVATE
|
||||
DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
PUBLIC
|
||||
DOCTEST_CONFIG_USE_STD_HEADERS
|
||||
$<$<BOOL:${BUILD_WITH_NO_EXCEPTIONS}>:
|
||||
DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS>)
|
||||
|
||||
#
|
||||
# fmt
|
||||
@@ -32,3 +36,33 @@ target_include_directories(${PROJECT_NAME}.fmt SYSTEM
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME}.fmt
|
||||
INTERFACE FMT_HEADER_ONLY)
|
||||
|
||||
#
|
||||
# gbench
|
||||
#
|
||||
|
||||
file(GLOB_RECURSE GBENCH_SOURCES CONFIGURE_DEPENDS "gbench/src/*.cc")
|
||||
add_library(${PROJECT_NAME}.gbench STATIC ${GBENCH_SOURCES})
|
||||
add_library(${PROJECT_NAME}::gbench ALIAS ${PROJECT_NAME}.gbench)
|
||||
|
||||
target_compile_features(${PROJECT_NAME}.gbench
|
||||
PUBLIC cxx_std_20)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}.gbench SYSTEM
|
||||
PUBLIC gbench/include)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME}.gbench
|
||||
PUBLIC BENCHMARK_STATIC_DEFINE)
|
||||
|
||||
#
|
||||
# vmath
|
||||
#
|
||||
|
||||
add_library(${PROJECT_NAME}.vmath.hpp INTERFACE)
|
||||
add_library(${PROJECT_NAME}::vmath.hpp ALIAS ${PROJECT_NAME}.vmath.hpp)
|
||||
|
||||
target_compile_features(${PROJECT_NAME}.vmath.hpp
|
||||
INTERFACE cxx_std_20)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}.vmath.hpp SYSTEM
|
||||
INTERFACE vmath.hpp/headers)
|
||||
|
||||
1
develop/vendors/gbench
vendored
Submodule
1
develop/vendors/gbench
vendored
Submodule
Submodule develop/vendors/gbench added at d572f47773
1
develop/vendors/vmath.hpp
vendored
Submodule
1
develop/vendors/vmath.hpp
vendored
Submodule
Submodule develop/vendors/vmath.hpp added at 4699938160
Reference in New Issue
Block a user