-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP add
<ureact/signal.hpp>
compilation time benchmark
- Loading branch information
Showing
3 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <catch2/catch_test_macros.hpp> | ||
#include <nanobench.h> | ||
|
||
#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 ); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <ureact/signal.hpp> | ||
|
||
#ifndef INCLUDE_ONLY | ||
|
||
# include <utility> | ||
|
||
template <size_t N> | ||
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 <typename S> | ||
using signal_t = member_signal<S>; | ||
# else | ||
template <typename S> | ||
using signal_t = ureact::signal<S>; | ||
# endif | ||
|
||
# if USE_DIFFERENT_TYPES | ||
template <size_t N> | ||
using Int = Int<N>; | ||
# else | ||
template <size_t N> | ||
using Int = int; | ||
# endif | ||
|
||
# if COPY_COUNT >= 1 | ||
signal_t<Int<1>> value1 | ||
# if INITIALIZE_SIGNALS | ||
= make_const( Int<1>{} ); | ||
# else | ||
; | ||
# endif | ||
# endif | ||
# if COPY_COUNT >= 2 | ||
signal_t<Int<2>> value2 | ||
# if INITIALIZE_SIGNALS | ||
= make_const( Int<2>{} ); | ||
# else | ||
; | ||
# endif | ||
# endif | ||
# if COPY_COUNT >= 3 | ||
signal_t<Int<3>> value3 | ||
# if INITIALIZE_SIGNALS | ||
= make_const( Int<3>{} ); | ||
# else | ||
; | ||
# endif | ||
# endif | ||
# if COPY_COUNT >= 4 | ||
signal_t<Int<4>> value4 | ||
# if INITIALIZE_SIGNALS | ||
= make_const( Int<4>{} ); | ||
# else | ||
; | ||
# endif | ||
# endif | ||
# if COPY_COUNT >= 5 | ||
signal_t<Int<5>> value5 | ||
# if INITIALIZE_SIGNALS | ||
= make_const( Int<5>{} ); | ||
# else | ||
; | ||
# endif | ||
# endif | ||
# if COPY_COUNT >= 6 | ||
signal_t<Int<6>> value6 | ||
# if INITIALIZE_SIGNALS | ||
= make_const( Int<6>{} ); | ||
# else | ||
; | ||
# endif | ||
# endif | ||
# if COPY_COUNT >= 7 | ||
signal_t<Int<7>> value7 | ||
# if INITIALIZE_SIGNALS | ||
= make_const( Int<7>{} ); | ||
# else | ||
; | ||
# endif | ||
# endif | ||
# if COPY_COUNT >= 8 | ||
signal_t<Int<8>> value8 | ||
# if INITIALIZE_SIGNALS | ||
= make_const( Int<8>{} ); | ||
# else | ||
; | ||
# endif | ||
# endif | ||
# if COPY_COUNT >= 9 | ||
signal_t<Int<9>> value9 | ||
# if INITIALIZE_SIGNALS | ||
= make_const( Int<9>{} ); | ||
# else | ||
; | ||
# endif | ||
# endif | ||
# if COPY_COUNT >= 10 | ||
signal_t<Int<10>> value10 | ||
# if INITIALIZE_SIGNALS | ||
= make_const( Int<10>{} ); | ||
# else | ||
; | ||
# endif | ||
# endif | ||
# if COPY_COUNT >= 11 | ||
signal_t<Int<11>> 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() | ||
{} |