-
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 transform_compilation benchmark
- Loading branch information
Showing
3 changed files
with
200 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,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() | ||
{} |
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,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 ); | ||
} | ||
} | ||
} |