From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/variant2/benchmark/benchmark1.cpp | 168 ++++++++++++++ src/boost/libs/variant2/benchmark/benchmark1.md | 267 +++++++++++++++++++++++ src/boost/libs/variant2/benchmark/benchmark2.cpp | 149 +++++++++++++ src/boost/libs/variant2/benchmark/benchmark2.md | 207 ++++++++++++++++++ 4 files changed, 791 insertions(+) create mode 100644 src/boost/libs/variant2/benchmark/benchmark1.cpp create mode 100644 src/boost/libs/variant2/benchmark/benchmark1.md create mode 100644 src/boost/libs/variant2/benchmark/benchmark2.cpp create mode 100644 src/boost/libs/variant2/benchmark/benchmark2.md (limited to 'src/boost/libs/variant2/benchmark') diff --git a/src/boost/libs/variant2/benchmark/benchmark1.cpp b/src/boost/libs/variant2/benchmark/benchmark1.cpp new file mode 100644 index 00000000..703f8911 --- /dev/null +++ b/src/boost/libs/variant2/benchmark/benchmark1.cpp @@ -0,0 +1,168 @@ +// Copyright 2019 Peter Dimov +// +// 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 defined(ONLY_V2) +# define NO_BV +# define NO_SV +#endif + +#if defined(ONLY_BV) +# define NO_V2 +# define NO_SV +#endif + +#if defined(ONLY_SV) +# define NO_V2 +# define NO_BV +#endif + +#if !defined(NO_V2) +#include +#endif + +#if !defined(NO_BV) +#include +#endif + +#if !defined(NO_SV) +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +template struct is_numeric: std::integral_constant::value || std::is_floating_point::value> +{ +}; + +template struct have_addition: std::integral_constant::value && is_numeric::value> +{ +}; + +template::value>> auto add( T const& t, U const& u ) +{ + return t + u; +} + +template::value>> double add( T const& /*t*/, U const& /*u*/ ) +{ + throw std::logic_error( "Invalid addition" ); +} + +inline double to_double( double const& v ) +{ + return v; +} + +#if !defined(NO_V2) + +template boost::variant2::variant operator+( boost::variant2::variant const& v1, boost::variant2::variant const& v2 ) +{ + return visit( [&]( auto const& x1, auto const & x2 ) -> boost::variant2::variant { return add( x1, x2 ); }, v1, v2 ); +} + +template double to_double( boost::variant2::variant const& v ) +{ + return boost::variant2::get( v ); +} + +#endif + +#if !defined(NO_BV) + +template boost::variant operator+( boost::variant const& v1, boost::variant const& v2 ) +{ + return boost::apply_visitor( [&]( auto const& x1, auto const & x2 ) -> boost::variant { return add( x1, x2 ); }, v1, v2 ); +} + +template double to_double( boost::variant const& v ) +{ + return boost::get( v ); +} + +#endif + +#if !defined(NO_SV) + +template std::variant operator+( std::variant const& v1, std::variant const& v2 ) +{ + return visit( [&]( auto const& x1, auto const & x2 ) -> std::variant { return add( x1, x2 ); }, v1, v2 ); +} + +template double to_double( std::variant const& v ) +{ + return std::get( v ); +} + +#endif + +template void test_( long long N ) +{ + std::vector w; + // lack of reserve is deliberate + + auto tp1 = std::chrono::high_resolution_clock::now(); + + for( long long i = 0; i < N; ++i ) + { + V v; + + if( i % 7 == 0 ) + { + v = i / 7; + } + else + { + v = i / 7.0; + } + + w.push_back( v ); + } + + V s = 0.0; + + for( long long i = 0; i < N; ++i ) + { + s = s + w[ i ]; + } + + auto tp2 = std::chrono::high_resolution_clock::now(); + + std::cout << std::setw( 6 ) << std::chrono::duration_cast( tp2 - tp1 ).count() << " ms; S=" << to_double( s ) << "\n"; +} + +template void test( long long N ) +{ + std::cout << "N=" << N << ":\n"; + + std::cout << " double: "; test_( N ); +#if !defined(NO_V2) + std::cout << " variant2: "; test_>( N ); +#endif +#if !defined(NO_BV) + std::cout << "boost::variant: "; test_>( N ); +#endif +#if !defined(NO_SV) + std::cout << " std::variant: "; test_>( N ); +#endif + + std::cout << '\n'; +} + +int main() +{ + long long const N = 100'000'000LL; + + test( N ); + test, std::map>( N ); +} diff --git a/src/boost/libs/variant2/benchmark/benchmark1.md b/src/boost/libs/variant2/benchmark/benchmark1.md new file mode 100644 index 00000000..aa3bb933 --- /dev/null +++ b/src/boost/libs/variant2/benchmark/benchmark1.md @@ -0,0 +1,267 @@ +# benchmark1.cpp results + +## VS 2017 15.9.7 64 bit (cl.exe 19.16, /EHsc /std:c++17) + +### /Od + +#### Compile time + +``` + variant2 (-DONLY_V2): 1837 ms +boost::variant (-DONLY_BV): 2627 ms + std::variant (-DONLY_SV): 1425 ms +``` + +#### Run time + +``` +N=100000000: + double: 9041 ms; S=7.14286e+14 + variant2: 48367 ms; S=7.14286e+14 +boost::variant: 102776 ms; S=7.14286e+14 + std::variant: 40590 ms; S=7.14286e+14 + +N=100000000: + double: 9029 ms; S=7.14286e+14 + variant2: 92962 ms; S=7.14286e+14 +boost::variant: 110441 ms; S=7.14286e+14 + std::variant: 92974 ms; S=7.14286e+14 +``` + +### /O2 /DNDEBUG + +#### Compile time + +``` + variant2 (-DONLY_V2): 2571 ms +boost::variant (-DONLY_BV): 3335 ms + std::variant (-DONLY_SV): 1903 ms +``` + +#### Run time + +``` +N=100000000: + double: 1949 ms; S=7.14286e+14 + variant2: 4176 ms; S=7.14286e+14 +boost::variant: 11312 ms; S=7.14286e+14 + std::variant: 4617 ms; S=7.14286e+14 + +N=100000000: + double: 1949 ms; S=7.14286e+14 + variant2: 11807 ms; S=7.14286e+14 +boost::variant: 15632 ms; S=7.14286e+14 + std::variant: 10725 ms; S=7.14286e+14 +``` + +## g++ 7.4.0 -std=c++17 (Cygwin 64 bit) + +### -O0 + +#### Compile time + +``` + variant2 (-DONLY_V2): 2734 ms +boost::variant (-DONLY_BV): 4308 ms + std::variant (-DONLY_SV): 2298 ms +``` + +#### Run time + +``` +N=100000000: + double: 3620 ms; S=7.14286e+14 + variant2: 29214 ms; S=7.14286e+14 +boost::variant: 88492 ms; S=7.14286e+14 + std::variant: 39510 ms; S=7.14286e+14 + +N=100000000: + double: 3642 ms; S=7.14286e+14 + variant2: 75822 ms; S=7.14286e+14 +boost::variant: 96680 ms; S=7.14286e+14 + std::variant: 66411 ms; S=7.14286e+14 +``` + +### -O1 + +#### Compile time + +``` + variant2 (-DONLY_V2): 2103 ms +boost::variant (-DONLY_BV): 3398 ms + std::variant (-DONLY_SV): 1841 ms +``` + +#### Run time + +``` +N=100000000: + double: 1576 ms; S=7.14286e+14 + variant2: 3424 ms; S=7.14286e+14 +boost::variant: 4356 ms; S=7.14286e+14 + std::variant: 3764 ms; S=7.14286e+14 + +N=100000000: + double: 1582 ms; S=7.14286e+14 + variant2: 9062 ms; S=7.14286e+14 +boost::variant: 9603 ms; S=7.14286e+14 + std::variant: 8825 ms; S=7.14286e+14 +``` + +### -O2 -DNDEBUG + +#### Compile time + +``` + variant2 (-DONLY_V2): 2276 ms +boost::variant (-DONLY_BV): 3647 ms + std::variant (-DONLY_SV): 2111 ms +``` + +#### Run time + +``` +N=100000000: + double: 1643 ms; S=7.14286e+14 + variant2: 3070 ms; S=7.14286e+14 +boost::variant: 3385 ms; S=7.14286e+14 + std::variant: 3880 ms; S=7.14286e+14 + +N=100000000: + double: 1622 ms; S=7.14286e+14 + variant2: 8101 ms; S=7.14286e+14 +boost::variant: 8611 ms; S=7.14286e+14 + std::variant: 8694 ms; S=7.14286e+14 +``` + +### -O3 -DNDEBUG + +#### Compile time + +``` + variant2 (-DONLY_V2): 2390 ms +boost::variant (-DONLY_BV): 3768 ms + std::variant (-DONLY_SV): 2094 ms +``` + +#### Run time + +``` +N=100000000: + double: 1611 ms; S=7.14286e+14 + variant2: 2975 ms; S=7.14286e+14 +boost::variant: 3232 ms; S=7.14286e+14 + std::variant: 3726 ms; S=7.14286e+14 + +N=100000000: + double: 1603 ms; S=7.14286e+14 + variant2: 8157 ms; S=7.14286e+14 +boost::variant: 8419 ms; S=7.14286e+14 + std::variant: 8659 ms; S=7.14286e+14 +``` + +## clang++ 5.0.1 -std=c++17 -stdlib=libc++ (Cygwin 64 bit) + +### -O0 + +#### Compile time + +``` + variant2 (-DONLY_V2): 2190 ms +boost::variant (-DONLY_BV): 3537 ms + std::variant (-DONLY_SV): 2151 ms +``` + +#### Run time + +``` +N=100000000: + double: 6063 ms; S=7.14286e+14 + variant2: 23616 ms; S=7.14286e+14 +boost::variant: 92730 ms; S=7.14286e+14 + std::variant: 23160 ms; S=7.14286e+14 + +N=100000000: + double: 6054 ms; S=7.14286e+14 + variant2: 52738 ms; S=7.14286e+14 +boost::variant: 96896 ms; S=7.14286e+14 + std::variant: 72595 ms; S=7.14286e+14 +``` + +### -O1 + +#### Compile time + +``` + variant2 (-DONLY_V2): 2722 ms +boost::variant (-DONLY_BV): 4337 ms + std::variant (-DONLY_SV): 2697 ms +``` + +#### Run time + +``` +N=100000000: + double: 2171 ms; S=7.14286e+14 + variant2: 9280 ms; S=7.14286e+14 +boost::variant: 51478 ms; S=7.14286e+14 + std::variant: 5642 ms; S=7.14286e+14 + +N=100000000: + double: 2171 ms; S=7.14286e+14 + variant2: 22166 ms; S=7.14286e+14 +boost::variant: 54084 ms; S=7.14286e+14 + std::variant: 14330 ms; S=7.14286e+14 +``` + +### -O2 -DNDEBUG + +#### Compile time + +``` + variant2 (-DONLY_V2): 2499 ms +boost::variant (-DONLY_BV): 3826 ms + std::variant (-DONLY_SV): 2645 ms +``` + +#### Run time + +``` +N=100000000: + double: 1604 ms; S=7.14286e+14 + variant2: 2726 ms; S=7.14286e+14 +boost::variant: 6662 ms; S=7.14286e+14 + std::variant: 3869 ms; S=7.14286e+14 + +N=100000000: + double: 1598 ms; S=7.14286e+14 + variant2: 8136 ms; S=7.14286e+14 +boost::variant: 9236 ms; S=7.14286e+14 + std::variant: 6279 ms; S=7.14286e+14 +``` + +### -O3 -DNDEBUG + +#### Compile time + +``` + variant2 (-DONLY_V2): 2509 ms +boost::variant (-DONLY_BV): 3845 ms + std::variant (-DONLY_SV): 2638 ms +``` + +#### Run time + +``` +N=100000000: + double: 1592 ms; S=7.14286e+14 + variant2: 2697 ms; S=7.14286e+14 +boost::variant: 6648 ms; S=7.14286e+14 + std::variant: 3826 ms; S=7.14286e+14 + +N=100000000: + double: 1614 ms; S=7.14286e+14 + variant2: 8035 ms; S=7.14286e+14 +boost::variant: 9221 ms; S=7.14286e+14 + std::variant: 6319 ms; S=7.14286e+14 +``` diff --git a/src/boost/libs/variant2/benchmark/benchmark2.cpp b/src/boost/libs/variant2/benchmark/benchmark2.cpp new file mode 100644 index 00000000..bea5f3a9 --- /dev/null +++ b/src/boost/libs/variant2/benchmark/benchmark2.cpp @@ -0,0 +1,149 @@ +// Copyright 2019 Peter Dimov +// +// 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 defined(ONLY_V2) +# define NO_BV +# define NO_SV +#endif + +#if defined(ONLY_BV) +# define NO_V2 +# define NO_SV +#endif + +#if defined(ONLY_SV) +# define NO_V2 +# define NO_BV +#endif + +#if !defined(NO_V2) +#include +#endif + +#if !defined(NO_BV) +#include +#endif + +#if !defined(NO_SV) +#include +#endif + +#include +#include +#include +#include +#include + +struct prefix +{ + int v_; +}; + +struct X1: prefix {}; +struct X2: prefix {}; +struct X3: prefix {}; +struct X4: prefix {}; +struct X5: prefix {}; +struct X6: prefix {}; +struct X7: prefix {}; +struct X8: prefix {}; +struct X9: prefix {}; +struct X10: prefix {}; +struct X11: prefix {}; +struct X12: prefix {}; + +inline int get_value( prefix const& v ) +{ + return v.v_; +} + +#if !defined(NO_V2) + +template int get_value( boost::variant2::variant const& v ) +{ + return visit( []( prefix const& x ) { return x.v_; }, v ); +} + +#endif + +#if !defined(NO_BV) + +template int get_value( boost::variant const& v ) +{ + return boost::apply_visitor( []( prefix const& x ) { return x.v_; }, v ); +} + +#endif + +#if !defined(NO_SV) + +template int get_value( std::variant const& v ) +{ + return visit( []( prefix const& x ) { return x.v_; }, v ); +} + +#endif + +template void test_( int N ) +{ + std::vector w; + // lack of reserve is deliberate + + auto tp1 = std::chrono::high_resolution_clock::now(); + + for( int i = 0; i < N / 12; ++i ) + { + w.push_back( X1{ i } ); + w.push_back( X2{ i } ); + w.push_back( X3{ i } ); + w.push_back( X4{ i } ); + w.push_back( X5{ i } ); + w.push_back( X6{ i } ); + w.push_back( X7{ i } ); + w.push_back( X8{ i } ); + w.push_back( X9{ i } ); + w.push_back( X10{ i } ); + w.push_back( X11{ i } ); + w.push_back( X12{ i } ); + } + + unsigned long long s = 0; + + for( std::size_t i = 0, n = w.size(); i < n; ++i ) + { + s = s + get_value( w[ i ] ); + } + + auto tp2 = std::chrono::high_resolution_clock::now(); + + std::cout << std::setw( 6 ) << std::chrono::duration_cast( tp2 - tp1 ).count() << " ms; S=" << s << "\n"; +} + +template void test( int N ) +{ + std::cout << "N=" << N << ":\n"; + + std::cout << " prefix: "; test_( N ); +#if !defined(NO_V2) + std::cout << " variant2: "; test_>( N ); +#endif +#if !defined(NO_BV) + std::cout << "boost::variant: "; test_>( N ); +#endif +#if !defined(NO_SV) + std::cout << " std::variant: "; test_>( N ); +#endif + + std::cout << '\n'; +} + +int main() +{ + int const N = 100'000'000; + + test( N ); +} diff --git a/src/boost/libs/variant2/benchmark/benchmark2.md b/src/boost/libs/variant2/benchmark/benchmark2.md new file mode 100644 index 00000000..9aad6488 --- /dev/null +++ b/src/boost/libs/variant2/benchmark/benchmark2.md @@ -0,0 +1,207 @@ +# benchmark2.cpp results + +## VS 2017 15.9.7 64 bit (cl.exe 19.16, /EHsc /std:c++17) + +### /Od + +#### Compile time + +``` + variant2 (-DONLY_V2): 1403 ms +boost::variant (-DONLY_BV): 2972 ms + std::variant (-DONLY_SV): 1057 ms +``` + +#### Run time + +``` +N=100000000: + prefix: 7016 ms; S=416666583333336 + variant2: 24723 ms; S=416666583333336 +boost::variant: 60438 ms; S=416666583333336 + std::variant: 20707 ms; S=416666583333336 +``` + +### /O2 /DNDEBUG + +#### Compile time + +``` + variant2 (-DONLY_V2): 1778 ms +boost::variant (-DONLY_BV): 3252 ms + std::variant (-DONLY_SV): 1372 ms +``` + +#### Run time + +``` +N=100000000: + prefix: 803 ms; S=416666583333336 + variant2: 2124 ms; S=416666583333336 +boost::variant: 6191 ms; S=416666583333336 + std::variant: 2193 ms; S=416666583333336 +``` + +## g++ 7.4.0 -std=c++17 (Cygwin 64 bit) + +### -O0 + +#### Compile time + +``` + variant2 (-DONLY_V2): 1739 ms +boost::variant (-DONLY_BV): 3113 ms + std::variant (-DONLY_SV): 1719 ms +``` + +#### Run time + +``` +N=100000000: + prefix: 5163 ms; S=416666583333336 + variant2: 20628 ms; S=416666583333336 +boost::variant: 43308 ms; S=416666583333336 + std::variant: 42375 ms; S=416666583333336 +``` + +### -O1 + +#### Compile time + +``` + variant2 (-DONLY_V2): 1484 ms +boost::variant (-DONLY_BV): 2947 ms + std::variant (-DONLY_SV): 1448 ms +``` + +#### Run time + +``` +N=100000000: + prefix: 781 ms; S=416666583333336 + variant2: 1992 ms; S=416666583333336 +boost::variant: 2249 ms; S=416666583333336 + std::variant: 4843 ms; S=416666583333336 +``` + +### -O2 -DNDEBUG + +#### Compile time + +``` + variant2 (-DONLY_V2): 1547 ms +boost::variant (-DONLY_BV): 2999 ms + std::variant (-DONLY_SV): 1528 ms +``` + +#### Run time + +``` +N=100000000: + prefix: 793 ms; S=416666583333336 + variant2: 1686 ms; S=416666583333336 +boost::variant: 1833 ms; S=416666583333336 + std::variant: 4340 ms; S=416666583333336 +``` + +### -O3 -DNDEBUG + +#### Compile time + +``` + variant2 (-DONLY_V2): 1595 ms +boost::variant (-DONLY_BV): 3084 ms + std::variant (-DONLY_SV): 1620 ms +``` + +#### Run time + +``` +N=100000000: + prefix: 853 ms; S=416666583333336 + variant2: 1681 ms; S=416666583333336 +boost::variant: 1773 ms; S=416666583333336 + std::variant: 3989 ms; S=416666583333336 +``` + +## clang++ 5.0.1 -std=c++17 -stdlib=libc++ (Cygwin 64 bit) + +### -O0 + +#### Compile time + +``` + variant2 (-DONLY_V2): 1578 ms +boost::variant (-DONLY_BV): 2623 ms + std::variant (-DONLY_SV): 1508 ms +``` + +#### Run time + +``` +N=100000000: + prefix: 4447 ms; S=416666583333336 + variant2: 16016 ms; S=416666583333336 +boost::variant: 42365 ms; S=416666583333336 + std::variant: 17817 ms; S=416666583333336 +``` + +### -O1 + +#### Compile time + +``` + variant2 (-DONLY_V2): 1841 ms +boost::variant (-DONLY_BV): 2919 ms + std::variant (-DONLY_SV): 1776 ms +``` + +#### Run time + +``` +N=100000000: + prefix: 1390 ms; S=416666583333336 + variant2: 5397 ms; S=416666583333336 +boost::variant: 23234 ms; S=416666583333336 + std::variant: 2807 ms; S=416666583333336 +``` + +### -O2 -DNDEBUG + +#### Compile time + +``` + variant2 (-DONLY_V2): 1766 ms +boost::variant (-DONLY_BV): 2817 ms + std::variant (-DONLY_SV): 1718 ms +``` + +#### Run time + +``` +N=100000000: + prefix: 604 ms; S=416666583333336 + variant2: 1625 ms; S=416666583333336 +boost::variant: 2735 ms; S=416666583333336 + std::variant: 2664 ms; S=416666583333336 +``` + +### -O3 -DNDEBUG + +#### Compile time + +``` + variant2 (-DONLY_V2): 1720 ms +boost::variant (-DONLY_BV): 2806 ms + std::variant (-DONLY_SV): 1737 ms +``` + +#### Run time + +``` +N=100000000: + prefix: 603 ms; S=416666583333336 + variant2: 1608 ms; S=416666583333336 +boost::variant: 2696 ms; S=416666583333336 + std::variant: 2668 ms; S=416666583333336 +``` -- cgit v1.2.3