From cf4e59a8b218cb11215260fe67176522e98f168b Mon Sep 17 00:00:00 2001 From: Krylov Yaroslav Date: Wed, 23 Aug 2023 19:22:52 +0400 Subject: [PATCH] WIP add `` compilation time benchmark --- tests/compilation_time/CMakeLists.txt | 1 + tests/compilation_time/signal.cpp | 106 +++++++++++++ .../compilation_time/test_samples/signal.cpp | 143 ++++++++++++++++++ 3 files changed, 250 insertions(+) create mode 100644 tests/compilation_time/signal.cpp create mode 100644 tests/compilation_time/test_samples/signal.cpp diff --git a/tests/compilation_time/CMakeLists.txt b/tests/compilation_time/CMakeLists.txt index 341cce3..f692ef6 100644 --- a/tests/compilation_time/CMakeLists.txt +++ b/tests/compilation_time/CMakeLists.txt @@ -13,6 +13,7 @@ target_sources( compiler_args.cpp std_headers_include_time.cpp ureact_headers_include_time.cpp + signal.cpp transform_compilation.cpp ) diff --git a/tests/compilation_time/signal.cpp b/tests/compilation_time/signal.cpp new file mode 100644 index 0000000..09888da --- /dev/null +++ b/tests/compilation_time/signal.cpp @@ -0,0 +1,106 @@ +// +// Copyright (C) 2020-2023 Krylov Yaroslav. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +#include +#include + +#include "compiler_args.hpp" + +TEST_CASE( "signal compilation time" ) +{ + using namespace std::chrono_literals; + + ankerl::nanobench::Bench bench; + bench.title( "signal compilation time" ); + //bench.relative( true ); + bench.performanceCounters( false ); + bench.timeUnit( 1ms, "ms" ); + bench.minEpochIterations( 1 ); + + std::vector compilers = { + Compiler{ gcc, 9 }, + Compiler{ gcc, 10 }, + Compiler{ gcc, 11 }, + Compiler{ gcc, 12 }, + Compiler{ clang, 11 }, + Compiler{ clang, 12 }, + Compiler{ clang, 13 }, + Compiler{ clang, 14 }, + }; + + const auto args = generateCompilerArgs( + compilers, { BuildConfiguration::Debug, BuildConfiguration::Release }, 17 ); + for( const auto& compilerArgs : args ) + { + const auto compilerString = compilerArgs.get_name(); + + [[maybe_unused]] const auto add_member_signal_test = [&]( const bool useMemberSignal, + const bool useDifferentTypes, + const bool initialize, + const size_t i ) { + std::string name = useMemberSignal ? "member_signal" : "signal"; + if( i > 1 ) + { + name += ' '; + name += useDifferentTypes ? "different" : "same"; + } + if( initialize ) + { + name += ' '; + name += "init"; + } + name += ' '; + name += 'x' + std::to_string( i ); + + perform_test( bench, + name + " (" + compilerString + ')', + CompilerArgs{ compilerArgs } // + .source( "signal_in_header.cpp" ) + .definition( + std::string{ "USE_MEMBER_SIGNAL=" } + ( useMemberSignal ? "1" : "0" ) ) + .definition( + std::string{ "USE_DIFFERENT_TYPES=" } + ( useDifferentTypes ? "1" : "0" ) ) + .definition( std::string{ "INITIALIZE_SIGNALS=" } + ( initialize ? "1" : "0" ) ) + .definition( std::string{ "COPY_COUNT=" } + std::to_string( i ) ) + // + ); + }; + + { + perform_test( bench, + std::string{ "std include" } + " (" + compilerString + ')', + CompilerArgs{ compilerArgs } // + .source( "include_std.cpp" ) + .definition( "INCLUDE_ALL" ) + // + ); + } + + { + perform_test( bench, + std::string{ "include" } + " (" + compilerString + ')', + CompilerArgs{ compilerArgs } // + .source( "signal_in_header.cpp" ) + .definition( "INCLUDE_ONLY" ) + // + ); + } + + for( const auto& initialize : { false, true } ) + { + for( const auto& useMemberSignal : { false, true } ) + { + add_member_signal_test( + useMemberSignal, false /*useDifferentTypes*/, initialize, 1 ); + add_member_signal_test( + useMemberSignal, true /*useDifferentTypes*/, initialize, 11 ); + add_member_signal_test( + useMemberSignal, false /*useDifferentTypes*/, initialize, 11 ); + } + } + } +} diff --git a/tests/compilation_time/test_samples/signal.cpp b/tests/compilation_time/test_samples/signal.cpp new file mode 100644 index 0000000..c2ca231 --- /dev/null +++ b/tests/compilation_time/test_samples/signal.cpp @@ -0,0 +1,143 @@ +// +// Copyright (C) 2020-2023 Krylov Yaroslav. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +#include + +#ifndef INCLUDE_ONLY + +# include + +template +struct Int +{ + int value; + + operator int() + { + return value; + } +}; + +using namespace ureact::default_context; + +class SignalUser +{ +public: +# if USE_MEMBER_SIGNAL + UREACT_USE_MEMBER_SIGNALS( SignalUser ); + template + using signal_t = member_signal; +# else + template + using signal_t = ureact::signal; +# endif + +# if USE_DIFFERENT_TYPES + template + using Int = Int; +# else + template + using Int = int; +# endif + +# if COPY_COUNT >= 1 + signal_t> value1 +# if INITIALIZE_SIGNALS + = make_const( Int<1>{} ); +# else + ; +# endif +# endif +# if COPY_COUNT >= 2 + signal_t> value2 +# if INITIALIZE_SIGNALS + = make_const( Int<2>{} ); +# else + ; +# endif +# endif +# if COPY_COUNT >= 3 + signal_t> value3 +# if INITIALIZE_SIGNALS + = make_const( Int<3>{} ); +# else + ; +# endif +# endif +# if COPY_COUNT >= 4 + signal_t> value4 +# if INITIALIZE_SIGNALS + = make_const( Int<4>{} ); +# else + ; +# endif +# endif +# if COPY_COUNT >= 5 + signal_t> value5 +# if INITIALIZE_SIGNALS + = make_const( Int<5>{} ); +# else + ; +# endif +# endif +# if COPY_COUNT >= 6 + signal_t> value6 +# if INITIALIZE_SIGNALS + = make_const( Int<6>{} ); +# else + ; +# endif +# endif +# if COPY_COUNT >= 7 + signal_t> value7 +# if INITIALIZE_SIGNALS + = make_const( Int<7>{} ); +# else + ; +# endif +# endif +# if COPY_COUNT >= 8 + signal_t> value8 +# if INITIALIZE_SIGNALS + = make_const( Int<8>{} ); +# else + ; +# endif +# endif +# if COPY_COUNT >= 9 + signal_t> value9 +# if INITIALIZE_SIGNALS + = make_const( Int<9>{} ); +# else + ; +# endif +# endif +# if COPY_COUNT >= 10 + signal_t> value10 +# if INITIALIZE_SIGNALS + = make_const( Int<10>{} ); +# else + ; +# endif +# endif +# if COPY_COUNT >= 11 + signal_t> value11 +# if INITIALIZE_SIGNALS + = make_const( Int<11>{} ); +# else + ; +# endif +# endif +# if COPY_COUNT >= 12 +# error "COPY_COUNT should be less than 12" +# endif +}; + +#endif + +int main() +{}