Skip to content

Commit

Permalink
WIP add transform_compilation benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikTH committed Aug 20, 2023
1 parent c7a9772 commit 7919272
Show file tree
Hide file tree
Showing 3 changed files with 200 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 @@ -12,6 +12,7 @@ target_sources(
PRIVATE #
compiler_args.cpp
std_headers_include_time.cpp
transform_compilation.cpp
)

target_link_libraries(
Expand Down
67 changes: 67 additions & 0 deletions tests/compilation_time/test_samples/transform.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// 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)
//
#if TRANSFORM_VERSION == 1
# include <ureact/adaptor/transform.hpp>
# define ADAPTOR_NAME transform
#endif

#ifndef INCLUDE_ONLY

# include <cassert>
# include <utility>

using namespace ureact;
using namespace ureact::default_context;

auto make_mult_by_n( int N )
{
return [N]( int value ) { return value * N; };
}

template <size_t N>
void test_function()
{
auto src = make_source<int>();
assert( src.is_valid() );

# ifndef MAKE_SOURCE_ONLY

const auto func = []() {
if constexpr( UNIQUE_FUNC )
return []( int value ) { return value * N; };
else
return make_mult_by_n( N );
}();

auto x = [&]() {
if constexpr( USE_PIPE )
return src | ADAPTOR_NAME( func );
else
return ADAPTOR_NAME( src, func );
}();

assert( x.is_valid() );

# endif
}

template <std::size_t... I>
void make_test_functions_impl( std::integer_sequence<std::size_t, I...> )
{
( test_function<I>(), ... );
}

void make_test_functions()
{
make_test_functions_impl( std::make_index_sequence<COPY_COUNT>{} );
}

#endif

int main()
{}
132 changes: 132 additions & 0 deletions tests/compilation_time/transform_compilation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//
// 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"

namespace
{

enum class FunctionType
{
unique,
shared
};

enum class AdapterType
{
pipe,
func
};

} // namespace

TEST_CASE( "transform compilation time" )
{
using namespace std::chrono_literals;

ankerl::nanobench::Bench bench;
bench.title( "transform 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::Default }, 17 );
for( const auto& compilerArgs : args )
{
const auto compilerString = compilerArgs.get_name();

const auto add_make_source_test = [&]( const int transformVersion, size_t i ) {
std::string name = "transform";
if( transformVersion > 1 )
name += std::to_string( transformVersion );

perform_test( bench,
std::string{ name + " make_source x" } + std::to_string( i ) + " (" + compilerString
+ ')',
CompilerArgs{ compilerArgs } //
.source( "transform.cpp" )
.definition( "TRANSFORM_VERSION=" + std::to_string( transformVersion ) )
.definition( "MAKE_SOURCE_ONLY" )
.definition( std::string{ "COPY_COUNT=" } + std::to_string( i ) )
//
);
};

const auto add_transform_test = [&]( const int transformVersion,
const size_t i,
FunctionType funcType,
AdapterType adapterType ) {
std::string name = "transform";
if( transformVersion > 1 )
name += std::to_string( transformVersion );
name += ' ';
if( i > 1 )
{
name += funcType == FunctionType::unique ? "unique" : "shared";
name += ' ';
}
name += adapterType == AdapterType::pipe ? "pipe" : "func";
name += ' ';
name += 'x' + std::to_string( i );

perform_test( bench,
name + " (" + compilerString + ')',
CompilerArgs{ compilerArgs } //
.source( "transform.cpp" )
.definition( "TRANSFORM_VERSION=" + std::to_string( transformVersion ) )
.definition( std::string{ "UNIQUE_FUNC=" }
+ ( funcType == FunctionType::unique ? "true" : "false" ) )
.definition( std::string{ "USE_PIPE=" }
+ ( adapterType == AdapterType::pipe ? "true" : "false" ) )
.definition( std::string{ "COPY_COUNT=" } + std::to_string( i ) )
//
);
};

for( const auto& transformVersion : { 1 } )
{
{
std::string name = "transform";
if( transformVersion > 1 )
name += std::to_string( transformVersion );
perform_test( bench,
std::string{ name + " include" } + " (" + compilerString + ')',
CompilerArgs{ compilerArgs } //
.source( "transform.cpp" )
.definition( "TRANSFORM_VERSION=" + std::to_string( transformVersion ) )
.definition( "INCLUDE_ONLY" )
//
);
}

add_make_source_test( transformVersion, 1 );
add_make_source_test( transformVersion, 11 );

add_transform_test( transformVersion, 1, FunctionType::unique, AdapterType::func );
add_transform_test( transformVersion, 1, FunctionType::unique, AdapterType::pipe );
add_transform_test( transformVersion, 11, FunctionType::shared, AdapterType::func );
add_transform_test( transformVersion, 11, FunctionType::shared, AdapterType::pipe );
add_transform_test( transformVersion, 11, FunctionType::unique, AdapterType::func );
add_transform_test( transformVersion, 11, FunctionType::unique, AdapterType::pipe );
}
}
}

0 comments on commit 7919272

Please sign in to comment.