From 6661912b9bb6b0cab0d2f63e94478c09c44258f4 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 10 Feb 2023 11:07:47 +0700 Subject: [PATCH] simple invoke bench --- develop/unbench/invoke_function_bench.cpp | 106 ++++++++++++++++++ develop/unbench/invoke_with_args_bench.cpp | 61 ---------- develop/unbench/invoke_without_args_bench.cpp | 55 --------- 3 files changed, 106 insertions(+), 116 deletions(-) create mode 100644 develop/unbench/invoke_function_bench.cpp delete mode 100644 develop/unbench/invoke_with_args_bench.cpp delete mode 100644 develop/unbench/invoke_without_args_bench.cpp diff --git a/develop/unbench/invoke_function_bench.cpp b/develop/unbench/invoke_function_bench.cpp new file mode 100644 index 0000000..33b6258 --- /dev/null +++ b/develop/unbench/invoke_function_bench.cpp @@ -0,0 +1,106 @@ +/******************************************************************************* + * 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 + +#include +#include + +namespace +{ + namespace meta = meta_hpp; + namespace vmath = vmath_hpp; + + volatile float static_acc{}; + volatile float static_angle{}; + + struct clazz { + static void static_function0() { + static_acc = static_acc + vmath::determinant(vmath::rotate(static_angle, vmath::unit3_x)); + static_angle = static_angle + 0.00001f; + } + + static void static_function1(float angle) { + static_acc = static_acc + vmath::determinant(vmath::rotate(angle, vmath::unit3_x)); + static_angle = static_angle + 0.00001f; + } + + static void static_function2(float angle, const vmath::fvec3& axis) { + static_acc = static_acc + vmath::determinant(vmath::rotate(angle, axis)); + static_angle = static_angle + 0.00001f; + } + + static void static_function3(float angle, const vmath::fvec3& axis, float mul) { + static_acc = static_acc + vmath::determinant(vmath::rotate(angle, axis)) * mul; + static_angle = static_angle + 0.00001f; + } + }; + + void invoke_function_reset(const benchmark::State&) { + static_acc = 0.f; + static_angle = 0.f; + } + + void invoke_function_static0(benchmark::State &state) { + for ( auto _ : state ) { + clazz::static_function0(); + } + } + + void invoke_function_static1(benchmark::State &state) { + for ( auto _ : state ) { + clazz::static_function1(static_angle); + } + } + + void invoke_function_static2(benchmark::State &state) { + for ( auto _ : state ) { + clazz::static_function2(static_angle, vmath::unit3_x); + } + } + + void invoke_function_static3(benchmark::State &state) { + for ( auto _ : state ) { + clazz::static_function3(static_angle, vmath::unit3_x, 2.f); + } + } + + void invoke_function_dynamic0(benchmark::State &state) { + for ( auto _ : state ) { + meta::invoke(&clazz::static_function0); + } + } + + void invoke_function_dynamic1(benchmark::State &state) { + for ( auto _ : state ) { + meta::invoke(&clazz::static_function1, static_angle); + } + } + + void invoke_function_dynamic2(benchmark::State &state) { + for ( auto _ : state ) { + meta::invoke(&clazz::static_function2, static_angle, vmath::unit3_x); + } + } + + void invoke_function_dynamic3(benchmark::State &state) { + for ( auto _ : state ) { + meta::invoke(&clazz::static_function3, static_angle, vmath::unit3_x, 2.f); + } + } +} + +BENCHMARK(invoke_function_static0)->Teardown(invoke_function_reset); +BENCHMARK(invoke_function_dynamic0)->Teardown(invoke_function_reset); + +BENCHMARK(invoke_function_static1)->Teardown(invoke_function_reset); +BENCHMARK(invoke_function_dynamic1)->Teardown(invoke_function_reset); + +BENCHMARK(invoke_function_static2)->Teardown(invoke_function_reset); +BENCHMARK(invoke_function_dynamic2)->Teardown(invoke_function_reset); + +BENCHMARK(invoke_function_static3)->Teardown(invoke_function_reset); +BENCHMARK(invoke_function_dynamic3)->Teardown(invoke_function_reset); diff --git a/develop/unbench/invoke_with_args_bench.cpp b/develop/unbench/invoke_with_args_bench.cpp deleted file mode 100644 index 222a91e..0000000 --- a/develop/unbench/invoke_with_args_bench.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * 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 - -#include -#include - -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_().function_("static_function", &clazz::static_function); - return meta::resolve_type().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); diff --git a/develop/unbench/invoke_without_args_bench.cpp b/develop/unbench/invoke_without_args_bench.cpp deleted file mode 100644 index b848420..0000000 --- a/develop/unbench/invoke_without_args_bench.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * 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 - -#include -#include - -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_().function_("static_function", &clazz::static_function); - return meta::resolve_type().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);