Skip to content

Commit

Permalink
WIP add <ureact/events.hpp> compilation time benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikTH committed Aug 23, 2023
1 parent e39f345 commit 0f2c5b7
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/compilation_time/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ target_sources(
std_headers_include_time.cpp
ureact_headers_include_time.cpp
signal.cpp
events.cpp
transform_compilation.cpp
)

Expand Down
106 changes: 106 additions & 0 deletions tests/compilation_time/events.cpp
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( "events compilation time" )
{
using namespace std::chrono_literals;

ankerl::nanobench::Bench bench;
bench.title( "events 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_events_test = [&]( const bool useMemberEvents,
const bool useDifferentTypes,
const bool initialize,
const size_t i ) {
std::string name = useMemberEvents ? "member_events" : "events";
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( "events.cpp" )
.definition(
std::string{ "USE_MEMBER_EVENTS=" } + ( useMemberEvents ? "1" : "0" ) )
.definition(
std::string{ "USE_DIFFERENT_TYPES=" } + ( useDifferentTypes ? "1" : "0" ) )
.definition( std::string{ "INITIALIZE_EVENTS=" } + ( 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( "events.cpp" )
.definition( "INCLUDE_ONLY" )
//
);
}

for( const auto& initialize : { false, true } )
{
for( const auto& useMemberEvents : { false, true } )
{
add_member_events_test(
useMemberEvents, false /*useDifferentTypes*/, initialize, 1 );
add_member_events_test(
useMemberEvents, false /*useDifferentTypes*/, initialize, 11 );
add_member_events_test(
useMemberEvents, true /*useDifferentTypes*/, initialize, 11 );
}
}
}
}
143 changes: 143 additions & 0 deletions tests/compilation_time/test_samples/events.cpp
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/events.hpp>

#ifndef INCLUDE_ONLY

# include <utility>

template <size_t N>
struct Int
{
int value;

operator int()
{
return value;
}
};

using namespace ureact::default_context;

class EventsUser
{
public:
# if USE_MEMBER_EVENTS
UREACT_USE_MEMBER_EVENTS( EventsUser );
template <typename E>
using events_t = member_events<E>;
# else
template <typename E>
using events_t = ureact::events<E>;
# 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
events_t<Int<1>> value1
# if INITIALIZE_EVENTS
= make_never<Int<1>>();
# else
;
# endif
# endif
# if COPY_COUNT >= 2
events_t<Int<2>> value2
# if INITIALIZE_EVENTS
= make_never<Int<2>>();
# else
;
# endif
# endif
# if COPY_COUNT >= 3
events_t<Int<3>> value3
# if INITIALIZE_EVENTS
= make_never<Int<3>>();
# else
;
# endif
# endif
# if COPY_COUNT >= 4
events_t<Int<4>> value4
# if INITIALIZE_EVENTS
= make_never<Int<4>>();
# else
;
# endif
# endif
# if COPY_COUNT >= 5
events_t<Int<5>> value5
# if INITIALIZE_EVENTS
= make_never<Int<5>>();
# else
;
# endif
# endif
# if COPY_COUNT >= 6
events_t<Int<6>> value6
# if INITIALIZE_EVENTS
= make_never<Int<6>>();
# else
;
# endif
# endif
# if COPY_COUNT >= 7
events_t<Int<7>> value7
# if INITIALIZE_EVENTS
= make_never<Int<7>>();
# else
;
# endif
# endif
# if COPY_COUNT >= 8
events_t<Int<8>> value8
# if INITIALIZE_EVENTS
= make_never<Int<8>>();
# else
;
# endif
# endif
# if COPY_COUNT >= 9
events_t<Int<9>> value9
# if INITIALIZE_EVENTS
= make_never<Int<9>>();
# else
;
# endif
# endif
# if COPY_COUNT >= 10
events_t<Int<10>> value10
# if INITIALIZE_EVENTS
= make_never<Int<10>>();
# else
;
# endif
# endif
# if COPY_COUNT >= 11
events_t<Int<11>> value11
# if INITIALIZE_EVENTS
= make_never<Int<11>>();
# else
;
# endif
# endif
# if COPY_COUNT >= 12
# error "COPY_COUNT should be less than 12"
# endif
};

#endif

int main()
{}

0 comments on commit 0f2c5b7

Please sign in to comment.