diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/hana/benchmark | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/hana/benchmark')
74 files changed, 2327 insertions, 0 deletions
diff --git a/src/boost/libs/hana/benchmark/CMakeLists.txt b/src/boost/libs/hana/benchmark/CMakeLists.txt new file mode 100644 index 000000000..212454563 --- /dev/null +++ b/src/boost/libs/hana/benchmark/CMakeLists.txt @@ -0,0 +1,91 @@ +# Copyright Louis Dionne 2013-2017 +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +############################################################################## +# Required packages, gems and caveats +############################################################################## +find_package(Ruby 2.1) +if(NOT ${RUBY_FOUND}) + message(WARNING "Ruby >= 2.1 was not found; the benchmarks will be unavailable.") + return() +endif() + +# Check for the 'ruby-progressbar' and 'tilt' gems +execute_process(COMMAND ${RUBY_EXECUTABLE} -r ruby-progressbar -r tilt -e "" + RESULT_VARIABLE __BOOST_HANA_MISSING_GEMS + OUTPUT_QUIET ERROR_QUIET) +if(${__BOOST_HANA_MISSING_GEMS}) + message(WARNING + "The 'ruby-progressbar' and/or 'tilt' gems were not found; " + "the benchmarks will be unavailable." + "Use `gem install ruby-progressbar tilt` to install the missing gems.") + return() +endif() + +# Some benchmarks depend on those libraries +find_package(MPL11) +find_package(Meta) + +include(CheckCXXCompilerFlag) +check_cxx_compiler_flag(-ftemplate-depth=-1 BOOST_HANA_HAS_FTEMPLATE_DEPTH) + +############################################################################## +# Configure the measure.rb script +############################################################################## +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/measure.in.rb #input + ${CMAKE_CURRENT_BINARY_DIR}/measure.rb #output + @ONLY) + +############################################################################## +# Add the benchmarks +############################################################################## +add_custom_target(benchmarks COMMENT "Generate all the benchmarks.") + +add_custom_target(travis_compiler_slug USES_TERMINAL + COMMAND ${CMAKE_COMMAND} -E echo "travis_compiler_slug: $<LOWER_CASE:${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}>") +add_custom_target(travis_config_slug USES_TERMINAL + COMMAND ${CMAKE_COMMAND} -E echo "travis_config_slug: $<LOWER_CASE:$<CONFIG>>") + +file(GLOB_RECURSE BOOST_HANA_BENCHMARKS *.erb.json) +foreach(benchmark IN LISTS BOOST_HANA_BENCHMARKS) + boost_hana_target_name_for(target ${benchmark} ".erb.json") + get_filename_component(directory "${benchmark}" DIRECTORY) + file(GLOB cpp_files "${directory}/*.erb.cpp") + configure_file("${benchmark}" "${CMAKE_CURRENT_BINARY_DIR}/${target}.erb.json" @ONLY) + + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${target}.measure.cpp" "") + add_executable(${target}.measure EXCLUDE_FROM_ALL "${CMAKE_CURRENT_BINARY_DIR}/${target}.measure.cpp") + target_include_directories(${target}.measure PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") + if (MPL11_FOUND) + target_include_directories(${target}.measure PRIVATE "${MPL11_INCLUDE_DIR}") + endif() + if (Meta_FOUND) + target_include_directories(${target}.measure PRIVATE "${Meta_INCLUDE_DIR}") + endif() + if (Boost_FOUND) + target_link_libraries(${target}.measure PRIVATE Boost::boost) + endif() + boost_hana_set_test_properties(${target}.measure) + if (BOOST_HANA_HAS_FTEMPLATE_DEPTH) + target_compile_options(${target}.measure PRIVATE -ftemplate-depth=-1) + endif() + set_target_properties(${target}.measure PROPERTIES RULE_LAUNCH_COMPILE "${CMAKE_CURRENT_BINARY_DIR}/measure.rb") + set_property(TARGET ${target}.measure APPEND PROPERTY INCLUDE_DIRECTORIES "${directory}") + add_custom_target(${target}.measure.run COMMAND ${target}.measure) + + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${target}.json" + COMMAND ${RUBY_EXECUTABLE} -r tilt -r "${CMAKE_CURRENT_BINARY_DIR}/measure.rb" + -e "MEASURE_FILE = '${CMAKE_CURRENT_BINARY_DIR}/${target}.measure.cpp'" + -e "MEASURE_TARGET = '${target}.measure'" + -e "json = Tilt::ERBTemplate.new('${CMAKE_CURRENT_BINARY_DIR}/${target}.erb.json').render" + -e "File.open('${CMAKE_CURRENT_BINARY_DIR}/${target}.json', 'w') { |f| f.write(json) } " + WORKING_DIRECTORY ${directory} + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${target}.erb.json" ${cpp_files} + VERBATIM USES_TERMINAL + COMMENT "Generating dataset for ${target}" + ) + + add_custom_target(${target} DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${target}.json") + add_dependencies(benchmarks ${target}) +endforeach() diff --git a/src/boost/libs/hana/benchmark/chart.html b/src/boost/libs/hana/benchmark/chart.html new file mode 100644 index 000000000..55718cefa --- /dev/null +++ b/src/boost/libs/hana/benchmark/chart.html @@ -0,0 +1,40 @@ +<!-- +Copyright Louis Dionne 2013-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +--> + +<!-- boost-no-inspect --> + +<!DOCTYPE html> +<html> +<head> + <meta http-equiv="content-type" content="text/html; charset=UTF-8"> + + <script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script> + <script type="text/javascript" src="../doc/js/highcharts.js"></script> + <script type="text/javascript" src="../doc/js/highcharts-data.js"></script> + <script type="text/javascript" src="../doc/js/highcharts-exporting.js"></script> + <script type="text/javascript" src="../doc/js/chart.js"></script> + + <script type="text/javascript"> + var redrawChart = function(dataset) { + var path = "../build/benchmark/benchmark." + dataset + ".json"; + $.getJSON(path, function(options) { + if ($("#container").highcharts()) + $("#container").highcharts().destroy(); + + Hana.initChart($("#container"), options); + $('#container').highcharts().redraw(); + }); + }; + </script> +</head> + +<body> + <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div> + + <input type="text" size=100 id="dataset" class="enter" value="" onchange="redrawChart(this.value)"/> +</body> + +</html> diff --git a/src/boost/libs/hana/benchmark/find_if/compile.erb.json b/src/boost/libs/hana/benchmark/find_if/compile.erb.json new file mode 100644 index 000000000..da6542b55 --- /dev/null +++ b/src/boost/libs/hana/benchmark/find_if/compile.erb.json @@ -0,0 +1,53 @@ +<% + hana = (0...50).step(5).to_a + (50..200).step(25).to_a + fusion = (0...50).step(5).to_a + mpl = hana + meta = hana +%> + +{ + "title": { + "text": "Compile-time behavior of find_if" + }, + "series": [ + { + "name": "hana::tuple", + "data": <%= time_compilation('compile.hana.tuple.erb.cpp', hana) %> + } + + <% if false %> + , { + "name": "hana::set", + "data": <%= time_compilation('compile.hana.set.erb.cpp', hana) %> + }, { + "name": "hana::map", + "data": <%= time_compilation('compile.hana.map.erb.cpp', hana) %> + } + <% end %> + + , { + "name": "std::integer_sequence", + "data": <%= time_compilation('compile.std.integer_sequence.erb.cpp', hana) %> + } + + <% if cmake_bool("@Boost_FOUND@") %> + , { + "name": "fusion::vector", + "data": <%= time_compilation('compile.fusion.vector.erb.cpp', fusion) %> + }, { + "name": "fusion::list", + "data": <%= time_compilation('compile.fusion.list.erb.cpp', fusion) %> + }, { + "name": "mpl::vector", + "data": <%= time_compilation('compile.mpl.vector.erb.cpp', mpl) %> + } + <% end %> + + <% if cmake_bool("@Meta_FOUND@") %> + , { + "name": "meta::list", + "data": <%= time_compilation('compile.meta.list.erb.cpp', meta) %> + } + <% end %> + ] +} diff --git a/src/boost/libs/hana/benchmark/find_if/compile.fusion.list.erb.cpp b/src/boost/libs/hana/benchmark/find_if/compile.fusion.list.erb.cpp new file mode 100644 index 000000000..a7c0ca90e --- /dev/null +++ b/src/boost/libs/hana/benchmark/find_if/compile.fusion.list.erb.cpp @@ -0,0 +1,30 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +<% if input_size > 10 %> + #define FUSION_MAX_LIST_SIZE <%= ((input_size + 9) / 10) * 10 %> +<% end %> + +#include <boost/fusion/include/find_if.hpp> +#include <boost/fusion/include/make_list.hpp> +#include <boost/mpl/integral_c.hpp> +namespace fusion = boost::fusion; +namespace mpl = boost::mpl; + + +struct is_last { + template <typename N> + struct apply + : mpl::integral_c<bool, N::type::value == <%= input_size %>> + { }; +}; + +int main() { + auto ints = fusion::make_list( + <%= (1..input_size).map { |n| "mpl::integral_c<int, #{n}>{}" }.join(', ') %> + ); + + auto result = fusion::find_if<is_last>(ints); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/find_if/compile.fusion.vector.erb.cpp b/src/boost/libs/hana/benchmark/find_if/compile.fusion.vector.erb.cpp new file mode 100644 index 000000000..067cbaae5 --- /dev/null +++ b/src/boost/libs/hana/benchmark/find_if/compile.fusion.vector.erb.cpp @@ -0,0 +1,30 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +<% if input_size > 10 %> + #define FUSION_MAX_VECTOR_SIZE <%= ((input_size + 9) / 10) * 10 %> +<% end %> + +#include <boost/fusion/include/find_if.hpp> +#include <boost/fusion/include/make_vector.hpp> +#include <boost/mpl/integral_c.hpp> +namespace fusion = boost::fusion; +namespace mpl = boost::mpl; + + +struct is_last { + template <typename N> + struct apply + : mpl::integral_c<bool, N::type::value == <%= input_size %>> + { }; +}; + +int main() { + auto ints = fusion::make_vector( + <%= (1..input_size).map { |n| "mpl::integral_c<int, #{n}>{}" }.join(', ') %> + ); + + auto result = fusion::find_if<is_last>(ints); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/find_if/compile.hana.map.erb.cpp b/src/boost/libs/hana/benchmark/find_if/compile.hana.map.erb.cpp new file mode 100644 index 000000000..8b600973f --- /dev/null +++ b/src/boost/libs/hana/benchmark/find_if/compile.hana.map.erb.cpp @@ -0,0 +1,29 @@ +// Copyright Jason Rice 2015 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/bool.hpp> +#include <boost/hana/find_if.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/map.hpp> +namespace hana = boost::hana; + + +struct is_last { + template <typename N> + constexpr auto operator()(N) const { + return hana::bool_c<N::value == <%= input_size %>>; + } +}; + +struct undefined {}; + +int main() { + constexpr auto map = hana::make_map( + <%= (1..input_size).map { |n| + "hana::make_pair(hana::int_c<#{n}>, undefined{})" + }.join(', ') %> + ); + constexpr auto result = hana::find_if(map, is_last{}); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/find_if/compile.hana.set.erb.cpp b/src/boost/libs/hana/benchmark/find_if/compile.hana.set.erb.cpp new file mode 100644 index 000000000..6ce318786 --- /dev/null +++ b/src/boost/libs/hana/benchmark/find_if/compile.hana.set.erb.cpp @@ -0,0 +1,25 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/bool.hpp> +#include <boost/hana/find_if.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/set.hpp> +namespace hana = boost::hana; + + +struct is_last { + template <typename N> + constexpr auto operator()(N) const { + return hana::bool_c<N::value == <%= input_size %>>; + } +}; + +int main() { + constexpr auto set = hana::make_set( + <%= (1..input_size).map { |n| "hana::int_c<#{n}>" }.join(', ') %> + ); + constexpr auto result = hana::find_if(set, is_last{}); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/find_if/compile.hana.tuple.erb.cpp b/src/boost/libs/hana/benchmark/find_if/compile.hana.tuple.erb.cpp new file mode 100644 index 000000000..7e4684b65 --- /dev/null +++ b/src/boost/libs/hana/benchmark/find_if/compile.hana.tuple.erb.cpp @@ -0,0 +1,24 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/bool.hpp> +#include <boost/hana/find_if.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/tuple.hpp> + + +struct is_last { + template <typename N> + constexpr auto operator()(N) const { + return boost::hana::bool_c<N::value == <%= input_size %>>; + } +}; + +int main() { + constexpr auto tuple = boost::hana::make_tuple( + <%= (1..input_size).map { |n| "boost::hana::int_c<#{n}>" }.join(', ') %> + ); + constexpr auto result = boost::hana::find_if(tuple, is_last{}); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/find_if/compile.meta.list.erb.cpp b/src/boost/libs/hana/benchmark/find_if/compile.meta.list.erb.cpp new file mode 100644 index 000000000..4c2e61aa7 --- /dev/null +++ b/src/boost/libs/hana/benchmark/find_if/compile.meta.list.erb.cpp @@ -0,0 +1,21 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <meta/meta.hpp> + + +struct is_last { + template <typename N> + using apply = meta::bool_<N::value == <%= input_size %>>; +}; + +using list = meta::list< + <%= (1..input_size).map { |i| "meta::int_<#{i}>" }.join(', ') %> +>; + +using result = meta::find_if<list, is_last>; + +int main() { + +} diff --git a/src/boost/libs/hana/benchmark/find_if/compile.mpl.vector.erb.cpp b/src/boost/libs/hana/benchmark/find_if/compile.mpl.vector.erb.cpp new file mode 100644 index 000000000..b6b42a702 --- /dev/null +++ b/src/boost/libs/hana/benchmark/find_if/compile.mpl.vector.erb.cpp @@ -0,0 +1,27 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/mpl/find_if.hpp> +#include <boost/mpl/integral_c.hpp> +#include <boost/mpl/push_back.hpp> +#include <boost/mpl/quote.hpp> +#include <boost/mpl/vector.hpp> +namespace mpl = boost::mpl; + + +struct is_last { + template <typename N> + struct apply + : mpl::integral_c<bool, N::type::value == <%= input_size %>> + { }; +}; + +using vector = <%= mpl_vector((1..input_size).to_a.map { |n| + "mpl::integral_c<int, #{n}>" +}) %>; + +using result = mpl::find_if<vector, is_last>::type; + + +int main() { } diff --git a/src/boost/libs/hana/benchmark/find_if/compile.std.integer_sequence.erb.cpp b/src/boost/libs/hana/benchmark/find_if/compile.std.integer_sequence.erb.cpp new file mode 100644 index 000000000..1e5194599 --- /dev/null +++ b/src/boost/libs/hana/benchmark/find_if/compile.std.integer_sequence.erb.cpp @@ -0,0 +1,27 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/bool.hpp> +#include <boost/hana/ext/std/integer_sequence.hpp> +#include <boost/hana/find_if.hpp> +#include <boost/hana/integral_constant.hpp> + +#include <utility> +namespace hana = boost::hana; + + +struct is_last { + template <typename N> + constexpr auto operator()(N) const { + return hana::bool_c<N::value == <%= input_size %>>; + } +}; + +int main() { + auto sequence = std::integer_sequence< + <%= (["int"] + (1..input_size).to_a).join(', ') %> + >{}; + auto result = hana::find_if(sequence, is_last{}); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/fold_left/bloat.erb.json b/src/boost/libs/hana/benchmark/fold_left/bloat.erb.json new file mode 100644 index 000000000..b3bd9892e --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/bloat.erb.json @@ -0,0 +1,38 @@ +<% + exec = (0..100).step(10).to_a + fusion = (0..50).step(10).to_a +%> + +{ + "title": { + "text": "Executable size for fold_left" + }, + "yAxis": { + "title": { + "text": "Executable size (kb)" + }, + "floor": 0 + }, + "tooltip": { + "valueSuffix": "kb" + }, + "series": [ + { + "name": "hana::tuple", + "data": <%= measure(:bloat, 'execute.hana.tuple.erb.cpp', exec) %> + }, { + "name": "std::vector", + "data": <%= measure(:bloat, 'execute.std.vector.erb.cpp', exec) %> + }, { + "name": "std::array", + "data": <%= measure(:bloat, 'execute.std.array.erb.cpp', exec) %> + } + + <% if cmake_bool("@Boost_FOUND@") %> + , { + "name": "fusion::vector", + "data": <%= measure(:bloat, 'execute.fusion.vector.erb.cpp', fusion) %> + } + <% end %> + ] +}
\ No newline at end of file diff --git a/src/boost/libs/hana/benchmark/fold_left/compile.cexpr.recursive.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/compile.cexpr.recursive.erb.cpp new file mode 100644 index 000000000..30beb1698 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/compile.cexpr.recursive.erb.cpp @@ -0,0 +1,53 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +template <typename ...xs> +struct list { }; + +template <typename T> +struct basic_type { using type = T; }; + +template <typename T> +constexpr basic_type<T> type{}; + + +template <typename x, typename ...xs> +constexpr auto head(list<x, xs...>) +{ return type<x>; } + +template <typename x, typename ...xs> +constexpr auto tail(list<x, xs...>) +{ return list<xs...>{}; } + +template <typename F, typename State, typename X, typename ...Xs> +constexpr auto foldl(F f, State s, list<X, Xs...> xs) +{ return foldl(f, f(s, head(xs)), tail(xs)); } + +template <typename F, typename State> +constexpr auto foldl(F, State s, list<>) +{ return s; } + +////////////////////////////////////////////////////////////////////////////// + + +struct f { + template <typename ...> + struct result { }; + + template <typename X, typename Y> + constexpr auto operator()(X, Y) const + { return result<X, Y>{}; } +}; + +template <int> struct x { }; +struct state { }; + +int main() { + constexpr auto xs = list< + <%= (1..input_size).map { |i| "x<#{i}>" }.join(', ') %> + >{}; + + constexpr auto result = foldl(f{}, state{}, xs); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/fold_left/compile.cexpr.unrolled.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/compile.cexpr.unrolled.erb.cpp new file mode 100644 index 000000000..80fb46f05 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/compile.cexpr.unrolled.erb.cpp @@ -0,0 +1,43 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/detail/variadic/foldl1.hpp> + + +template <typename ...xs> +struct list { }; + +template <typename T> +struct basic_type { using type = T; }; + +template <typename T> +constexpr basic_type<T> type{}; + + +template <typename F, typename State, typename ...Xs> +constexpr auto foldl(F f, State s, list<Xs...> xs) +{ return boost::hana::detail::variadic::foldl(f, s, type<Xs>...); } + +////////////////////////////////////////////////////////////////////////////// + +struct f { + template <typename ...> + struct result { }; + + template <typename X, typename Y> + constexpr auto operator()(X, Y) const + { return result<X, Y>{}; } +}; + +template <int> struct x { }; +struct state { }; + +int main() { + constexpr auto xs = list< + <%= (1..input_size).map { |i| "x<#{i}>" }.join(', ') %> + >{}; + + constexpr auto result = foldl(f{}, state{}, xs); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/fold_left/compile.erb.json b/src/boost/libs/hana/benchmark/fold_left/compile.erb.json new file mode 100644 index 000000000..7240907a9 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/compile.erb.json @@ -0,0 +1,61 @@ +<% + hana = (0...50).step(5).to_a + (50..400).step(25).to_a + fusion = (0..50).step(5) + mpl = hana + mpl11 = (0...50).step(5).to_a + (50..500).step(25).to_a + meta = (0...50).step(5).to_a + (50..200).step(25).to_a + cexpr = (0...50).step(5).to_a + (50..200).step(25).to_a +%> + + +{ + "title": { + "text": "Compile-time behavior of fold_left" + }, + "series": [ + { + "name": "hana::tuple", + "data": <%= time_compilation('compile.hana.tuple.erb.cpp', hana) %> + }, { + "name": "hana::basic_tuple", + "data": <%= time_compilation('compile.hana.basic_tuple.erb.cpp', hana) %> + } + + <% if cmake_bool("@Boost_FOUND@") %> + , { + "name": "fusion::vector", + "data": <%= time_compilation('compile.fusion.vector.erb.cpp', fusion) %> + },{ + "name": "fusion::list", + "data": <%= time_compilation('compile.fusion.list.erb.cpp', fusion) %> + }, { + "name": "mpl::vector", + "data": <%= time_compilation('compile.mpl.vector.erb.cpp', mpl) %> + } + <% end %> + + <% if cmake_bool("@MPL11_FOUND@") %> + , { + "name": "mpl11::list", + "data": <%= time_compilation('compile.mpl11.list.erb.cpp', mpl11) %> + } + <% end %> + + <% if cmake_bool("@Meta_FOUND@") %> + , { + "name": "meta::list", + "data": <%= time_compilation('compile.meta.list.erb.cpp', meta) %> + } + <% end %> + + <% if false %> + , { + "name": "cexpr::list (recursive)", + "data": <%= time_compilation('compile.cexpr.recursive.erb.cpp', cexpr) %> + }, { + "name": "cexpr::list (unrolled)", + "data": <%= time_compilation('compile.cexpr.unrolled.erb.cpp', cexpr) %> + } + <% end %> + ] +} diff --git a/src/boost/libs/hana/benchmark/fold_left/compile.fusion.list.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/compile.fusion.list.erb.cpp new file mode 100644 index 000000000..144744a23 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/compile.fusion.list.erb.cpp @@ -0,0 +1,31 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +<% if input_size > 10 %> + #define FUSION_MAX_LIST_SIZE <%= ((input_size + 9) / 10) * 10 %> +<% end %> + +#include <boost/fusion/include/fold.hpp> +#include <boost/fusion/include/make_list.hpp> +namespace fusion = boost::fusion; + + +struct f { + template <typename State, typename X> + constexpr X operator()(State, X x) const { return x; } +}; + +struct state { }; + +template <int i> +struct x { }; + +int main() { + auto xs = fusion::make_list( + <%= (1..input_size).map { |n| "x<#{n}>{}" }.join(', ') %> + ); + + auto result = fusion::fold(xs, state{}, f{}); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/fold_left/compile.fusion.vector.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/compile.fusion.vector.erb.cpp new file mode 100644 index 000000000..3a319b351 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/compile.fusion.vector.erb.cpp @@ -0,0 +1,31 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +<% if input_size > 10 %> + #define FUSION_MAX_VECTOR_SIZE <%= ((input_size + 9) / 10) * 10 %> +<% end %> + +#include <boost/fusion/include/fold.hpp> +#include <boost/fusion/include/make_vector.hpp> +namespace fusion = boost::fusion; + + +struct f { + template <typename State, typename X> + constexpr X operator()(State, X x) const { return x; } +}; + +struct state { }; + +template <int i> +struct x { }; + +int main() { + auto xs = fusion::make_vector( + <%= (1..input_size).map { |n| "x<#{n}>{}" }.join(', ') %> + ); + + auto result = fusion::fold(xs, state{}, f{}); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/fold_left/compile.hana.basic_tuple.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/compile.hana.basic_tuple.erb.cpp new file mode 100644 index 000000000..c076f3fc9 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/compile.hana.basic_tuple.erb.cpp @@ -0,0 +1,26 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/fold_left.hpp> +#include <boost/hana/basic_tuple.hpp> +namespace hana = boost::hana; + + +struct f { + template <typename State, typename X> + constexpr X operator()(State, X x) const { return x; } +}; + +struct state { }; + +template <int i> +struct x { }; + +int main() { + constexpr auto tuple = hana::make_basic_tuple( + <%= (1..input_size).map { |n| "x<#{n}>{}" }.join(', ') %> + ); + constexpr auto result = hana::fold_left(tuple, state{}, f{}); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/fold_left/compile.hana.tuple.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/compile.hana.tuple.erb.cpp new file mode 100644 index 000000000..a245e30c9 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/compile.hana.tuple.erb.cpp @@ -0,0 +1,25 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/fold_left.hpp> +#include <boost/hana/tuple.hpp> + + +struct f { + template <typename State, typename X> + constexpr X operator()(State, X x) const { return x; } +}; + +struct state { }; + +template <int i> +struct x { }; + +int main() { + constexpr auto tuple = boost::hana::make_tuple( + <%= (1..input_size).map { |n| "x<#{n}>{}" }.join(', ') %> + ); + constexpr auto result = boost::hana::fold_left(tuple, state{}, f{}); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/fold_left/compile.meta.list.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/compile.meta.list.erb.cpp new file mode 100644 index 000000000..cd2ec0f8a --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/compile.meta.list.erb.cpp @@ -0,0 +1,25 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <meta/meta.hpp> + + +struct f { + template <typename, typename> + struct apply; +}; + +template <int> struct x; + +struct state; + +using list = meta::list< + <%= (1..input_size).map { |i| "x<#{i}>" }.join(', ') %> +>; + +using result = meta::fold<list, state, f>; + +int main() { + +} diff --git a/src/boost/libs/hana/benchmark/fold_left/compile.mpl.vector.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/compile.mpl.vector.erb.cpp new file mode 100644 index 000000000..4d5b5b4b6 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/compile.mpl.vector.erb.cpp @@ -0,0 +1,24 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/mpl/fold.hpp> +#include <boost/mpl/push_back.hpp> +#include <boost/mpl/quote.hpp> +#include <boost/mpl/vector.hpp> + + +template <typename State, typename X> +struct f { using type = X; }; + +struct state { }; + +template <int i> +struct t { }; + +using vector = <%= mpl_vector((1..input_size).to_a.map { |n| "t<#{n}>" }) %>; + +using result = boost::mpl::fold<vector, state, boost::mpl::quote2<f>>::type; + + +int main() { } diff --git a/src/boost/libs/hana/benchmark/fold_left/compile.mpl11.list.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/compile.mpl11.list.erb.cpp new file mode 100644 index 000000000..cf383ef00 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/compile.mpl11.list.erb.cpp @@ -0,0 +1,26 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/mpl11/list.hpp> + + +struct f { + using type = f; + template <typename, typename> + struct apply { struct type; }; +}; + +template <int> struct x { struct type; }; + +struct state { struct type; }; + +using list = boost::mpl11::list< + <%= (1..input_size).map { |i| "x<#{i}>" }.join(', ') %> +>; + +using result = boost::mpl11::foldl<f, state, list>::type; + +int main() { + +} diff --git a/src/boost/libs/hana/benchmark/fold_left/execute.erb.json b/src/boost/libs/hana/benchmark/fold_left/execute.erb.json new file mode 100644 index 000000000..2f7d94559 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/execute.erb.json @@ -0,0 +1,32 @@ +<% + exec = (0..100).step(10).to_a + fusion = (0..50).step(10).to_a +%> + +{ + "title": { + "text": "Runtime behavior of fold_left" + }, + "series": [ + { + "name": "hana::tuple", + "data": <%= time_execution('execute.hana.tuple.erb.cpp', exec) %> + }, { + "name": "std::vector", + "data": <%= time_execution('execute.std.vector.erb.cpp', exec) %> + }, { + "name": "std::array", + "data": <%= time_execution('execute.std.array.erb.cpp', exec) %> + } + + <% if cmake_bool("@Boost_FOUND@") %> + , { + "name": "fusion::vector", + "data": <%= time_execution('execute.fusion.vector.erb.cpp', fusion) %> + }, { + "name": "fusion::list", + "data": <%= time_execution('execute.fusion.list.erb.cpp', fusion) %> + } + <% end %> + ] +}
\ No newline at end of file diff --git a/src/boost/libs/hana/benchmark/fold_left/execute.fusion.list.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/execute.fusion.list.erb.cpp new file mode 100644 index 000000000..b71938980 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/execute.fusion.list.erb.cpp @@ -0,0 +1,32 @@ +// Copyright Louis Dionne 2013-2017 +// Copyright Zach Laine 2014 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +<% if input_size > 10 %> + #define FUSION_MAX_LIST_SIZE <%= ((input_size + 9) / 10) * 10 %> +<% end %> + +#include <boost/fusion/include/fold.hpp> +#include <boost/fusion/include/make_list.hpp> + +#include "measure.hpp" +#include <cstdlib> +namespace fusion = boost::fusion; +namespace hana = boost::hana; + + +int main () { + hana::benchmark::measure([] { + long double result = 0; + for (int iteration = 0; iteration < 1 << 10; ++iteration) { + auto values = fusion::make_list( + <%= input_size.times.map { 'std::rand()' }.join(', ') %> + ); + + result += fusion::fold(values, 0, [](auto state, auto t) { + return state + t; + }); + } + }); +} diff --git a/src/boost/libs/hana/benchmark/fold_left/execute.fusion.vector.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/execute.fusion.vector.erb.cpp new file mode 100644 index 000000000..c733a3be0 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/execute.fusion.vector.erb.cpp @@ -0,0 +1,32 @@ +// Copyright Louis Dionne 2013-2017 +// Copyright Zach Laine 2014 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +<% if input_size > 10 %> + #define FUSION_MAX_VECTOR_SIZE <%= ((input_size + 9) / 10) * 10 %> +<% end %> + +#include <boost/fusion/include/fold.hpp> +#include <boost/fusion/include/make_vector.hpp> + +#include "measure.hpp" +#include <cstdlib> +namespace fusion = boost::fusion; +namespace hana = boost::hana; + + +int main () { + hana::benchmark::measure([] { + long double result = 0; + for (int iteration = 0; iteration < 1 << 10; ++iteration) { + auto values = fusion::make_vector( + <%= input_size.times.map { 'std::rand()' }.join(', ') %> + ); + + result += fusion::fold(values, 0, [](auto state, auto t) { + return state + t; + }); + } + }); +} diff --git a/src/boost/libs/hana/benchmark/fold_left/execute.hana.tuple.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/execute.hana.tuple.erb.cpp new file mode 100644 index 000000000..622d74f88 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/execute.hana.tuple.erb.cpp @@ -0,0 +1,26 @@ +// Copyright Louis Dionne 2013-2017 +// Copyright Zach Laine 2014 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/fold_left.hpp> +#include <boost/hana/tuple.hpp> + +#include "measure.hpp" +#include <cstdlib> + + +int main () { + boost::hana::benchmark::measure([] { + long double result = 0; + for (int iteration = 0; iteration < 1 << 10; ++iteration) { + auto values = boost::hana::make_tuple( + <%= input_size.times.map { 'std::rand()' }.join(', ') %> + ); + + result += boost::hana::fold_left(values, 0, [](auto state, auto t) { + return state + t; + }); + } + }); +} diff --git a/src/boost/libs/hana/benchmark/fold_left/execute.std.array.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/execute.std.array.erb.cpp new file mode 100644 index 000000000..3961151b6 --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/execute.std.array.erb.cpp @@ -0,0 +1,22 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include "measure.hpp" +#include <array> +#include <cstdlib> +#include <numeric> + + +int main () { + boost::hana::benchmark::measure([] { + long long result = 0; + for (int iteration = 0; iteration < 1 << 10; ++iteration) { + std::array<int, <%= input_size %>> values = {{ + <%= input_size.times.map { 'std::rand()' }.join(', ') %> + }}; + + result += std::accumulate(values.begin(), values.end(), 0); + } + }); +} diff --git a/src/boost/libs/hana/benchmark/fold_left/execute.std.vector.erb.cpp b/src/boost/libs/hana/benchmark/fold_left/execute.std.vector.erb.cpp new file mode 100644 index 000000000..703b6fbcc --- /dev/null +++ b/src/boost/libs/hana/benchmark/fold_left/execute.std.vector.erb.cpp @@ -0,0 +1,22 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include "measure.hpp" +#include <cstdlib> +#include <numeric> +#include <vector> + + +int main () { + boost::hana::benchmark::measure([] { + long long result = 0; + for (int iteration = 0; iteration < 1 << 10; ++iteration) { + std::vector<int> values = { + <%= input_size.times.map { 'std::rand()' }.join(', ') %> + }; + + result += std::accumulate(values.begin(), values.end(), 0); + } + }); +} diff --git a/src/boost/libs/hana/benchmark/including/baseline.erb.cpp b/src/boost/libs/hana/benchmark/including/baseline.erb.cpp new file mode 100644 index 000000000..932facb47 --- /dev/null +++ b/src/boost/libs/hana/benchmark/including/baseline.erb.cpp @@ -0,0 +1,6 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + + +int main() { } diff --git a/src/boost/libs/hana/benchmark/including/compile.erb.json b/src/boost/libs/hana/benchmark/including/compile.erb.json new file mode 100644 index 000000000..2441a4ee1 --- /dev/null +++ b/src/boost/libs/hana/benchmark/including/compile.erb.json @@ -0,0 +1,73 @@ +<% + def self.avg(xs) + xs.inject(0, :+) / xs.length + end + + def self.amortize(file) + # We remove the first one to mitigate cache effects + times = time_compilation(file, 6.times) + times.shift + avg(times.map { |_, t| t }) + end +%> + +{ + "chart": { + "type": "column" + }, + "legend": { + "enabled": false + }, + "xAxis": { + "type": "category" + }, + "title": { + "text": "Including various metaprogramming libraries" + }, + "plotOptions": { + "series": { + "borderWidth": 0, + "dataLabels": { + "enabled": true, + "format": "{point.y:.5f}s" + } + } + }, + "series": [{ + "name": "Include time", + "colorByPoint": true, + "data": [ + { + "name": "Baseline (no includes)", + "y": <%= amortize('baseline.erb.cpp') %> + }, { + "name": "Boost.Hana", + "y": <%= amortize('hana.erb.cpp') %> + } + + <% if cmake_bool("@Boost_FOUND@") %> + , { + "name": "Boost.MPL", + "y": <%= amortize('mpl.erb.cpp') %> + }, { + "name": "Boost.Fusion", + "y": <%= amortize('fusion.erb.cpp') %> + } + <% end %> + + <% if cmake_bool("@MPL11_FOUND@") %> + , { + "name": "MPL11", + "y": <%= amortize('mpl11.erb.cpp') %> + } + <% end %> + + <% if cmake_bool("@Meta_FOUND@") %> + , { + "name": "Meta", + "y": <%= amortize('meta.erb.cpp') %> + } + <% end %> + ] + }] +} diff --git a/src/boost/libs/hana/benchmark/including/fusion.erb.cpp b/src/boost/libs/hana/benchmark/including/fusion.erb.cpp new file mode 100644 index 000000000..bae08353a --- /dev/null +++ b/src/boost/libs/hana/benchmark/including/fusion.erb.cpp @@ -0,0 +1,16 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/fusion/adapted.hpp> +#include <boost/fusion/algorithm.hpp> +#include <boost/fusion/container.hpp> +#include <boost/fusion/functional.hpp> +#include <boost/fusion/iterator.hpp> +#include <boost/fusion/sequence.hpp> +#include <boost/fusion/support.hpp> +#include <boost/fusion/tuple.hpp> +#include <boost/fusion/view.hpp> + + +int main() { } diff --git a/src/boost/libs/hana/benchmark/including/hana.erb.cpp b/src/boost/libs/hana/benchmark/including/hana.erb.cpp new file mode 100644 index 000000000..e35e81350 --- /dev/null +++ b/src/boost/libs/hana/benchmark/including/hana.erb.cpp @@ -0,0 +1,8 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana.hpp> + + +int main() { } diff --git a/src/boost/libs/hana/benchmark/including/meta.erb.cpp b/src/boost/libs/hana/benchmark/including/meta.erb.cpp new file mode 100644 index 000000000..492d2f9ed --- /dev/null +++ b/src/boost/libs/hana/benchmark/including/meta.erb.cpp @@ -0,0 +1,8 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <meta/meta.hpp> + + +int main() { } diff --git a/src/boost/libs/hana/benchmark/including/mpl.erb.cpp b/src/boost/libs/hana/benchmark/including/mpl.erb.cpp new file mode 100644 index 000000000..167eb3765 --- /dev/null +++ b/src/boost/libs/hana/benchmark/including/mpl.erb.cpp @@ -0,0 +1,155 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/mpl/accumulate.hpp> +#include <boost/mpl/advance.hpp> +#include <boost/mpl/alias.hpp> +#include <boost/mpl/always.hpp> +#include <boost/mpl/and.hpp> +#include <boost/mpl/apply.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/arg.hpp> +#include <boost/mpl/arithmetic.hpp> +#include <boost/mpl/as_sequence.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/back.hpp> +#include <boost/mpl/back_inserter.hpp> +#include <boost/mpl/base.hpp> +#include <boost/mpl/begin.hpp> +#include <boost/mpl/bind.hpp> +#include <boost/mpl/bitand.hpp> +#include <boost/mpl/bitor.hpp> +#include <boost/mpl/bitwise.hpp> +#include <boost/mpl/bitxor.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/clear.hpp> +#include <boost/mpl/comparison.hpp> +#include <boost/mpl/contains.hpp> +#include <boost/mpl/copy.hpp> +#include <boost/mpl/copy_if.hpp> +#include <boost/mpl/count.hpp> +#include <boost/mpl/count_if.hpp> +#include <boost/mpl/deque.hpp> +#include <boost/mpl/deref.hpp> +#include <boost/mpl/distance.hpp> +#include <boost/mpl/divides.hpp> +#include <boost/mpl/empty.hpp> +#include <boost/mpl/empty_base.hpp> +#include <boost/mpl/empty_sequence.hpp> +#include <boost/mpl/end.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/erase.hpp> +#include <boost/mpl/erase_key.hpp> +#include <boost/mpl/eval_if.hpp> +#include <boost/mpl/filter_view.hpp> +#include <boost/mpl/find.hpp> +#include <boost/mpl/find_if.hpp> +#include <boost/mpl/fold.hpp> +#include <boost/mpl/for_each.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/front_inserter.hpp> +#include <boost/mpl/greater.hpp> +#include <boost/mpl/greater_equal.hpp> +#include <boost/mpl/has_key.hpp> +#include <boost/mpl/has_xxx.hpp> +#include <boost/mpl/identity.hpp> +#include <boost/mpl/if.hpp> +#include <boost/mpl/index_if.hpp> +#include <boost/mpl/index_of.hpp> +#include <boost/mpl/inherit.hpp> +#include <boost/mpl/inherit_linearly.hpp> +#include <boost/mpl/insert.hpp> +#include <boost/mpl/insert_range.hpp> +#include <boost/mpl/inserter.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/integral_c.hpp> +#include <boost/mpl/integral_c_tag.hpp> +#include <boost/mpl/is_placeholder.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/mpl/iter_fold.hpp> +#include <boost/mpl/iter_fold_if.hpp> +#include <boost/mpl/iterator_category.hpp> +#include <boost/mpl/iterator_range.hpp> +#include <boost/mpl/iterator_tags.hpp> +#include <boost/mpl/joint_view.hpp> +#include <boost/mpl/key_type.hpp> +#include <boost/mpl/lambda.hpp> +#include <boost/mpl/less.hpp> +#include <boost/mpl/less_equal.hpp> +#include <boost/mpl/list.hpp> +#include <boost/mpl/list_c.hpp> +#include <boost/mpl/logical.hpp> +#include <boost/mpl/long.hpp> +#include <boost/mpl/lower_bound.hpp> +#include <boost/mpl/map.hpp> +#include <boost/mpl/max.hpp> +#include <boost/mpl/max_element.hpp> +#include <boost/mpl/min.hpp> +#include <boost/mpl/min_element.hpp> +#include <boost/mpl/min_max.hpp> +#include <boost/mpl/minus.hpp> +#include <boost/mpl/modulus.hpp> +#include <boost/mpl/multiplies.hpp> +#include <boost/mpl/negate.hpp> +#include <boost/mpl/next.hpp> +#include <boost/mpl/next_prior.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/not_equal_to.hpp> +#include <boost/mpl/numeric_cast.hpp> +#include <boost/mpl/O1_size.hpp> +#include <boost/mpl/or.hpp> +#include <boost/mpl/order.hpp> +#include <boost/mpl/pair.hpp> +#include <boost/mpl/pair_view.hpp> +#include <boost/mpl/partition.hpp> +#include <boost/mpl/placeholders.hpp> +#include <boost/mpl/plus.hpp> +#include <boost/mpl/pop_back.hpp> +#include <boost/mpl/pop_front.hpp> +#include <boost/mpl/print.hpp> +#include <boost/mpl/prior.hpp> +#include <boost/mpl/protect.hpp> +#include <boost/mpl/push_back.hpp> +#include <boost/mpl/push_front.hpp> +#include <boost/mpl/quote.hpp> +#include <boost/mpl/range_c.hpp> +#include <boost/mpl/remove.hpp> +#include <boost/mpl/remove_if.hpp> +#include <boost/mpl/replace.hpp> +#include <boost/mpl/replace_if.hpp> +#include <boost/mpl/reverse.hpp> +#include <boost/mpl/reverse_fold.hpp> +#include <boost/mpl/reverse_iter_fold.hpp> +#include <boost/mpl/same_as.hpp> +#include <boost/mpl/sequence_tag.hpp> +#include <boost/mpl/set.hpp> +#include <boost/mpl/set_c.hpp> +#include <boost/mpl/shift_left.hpp> +#include <boost/mpl/shift_right.hpp> +#include <boost/mpl/single_view.hpp> +#include <boost/mpl/size.hpp> +#include <boost/mpl/size_t.hpp> +#include <boost/mpl/sizeof.hpp> +#include <boost/mpl/sort.hpp> +#include <boost/mpl/stable_partition.hpp> +#include <boost/mpl/string.hpp> +#include <boost/mpl/switch.hpp> +#include <boost/mpl/tag.hpp> +#include <boost/mpl/times.hpp> +#include <boost/mpl/transform.hpp> +#include <boost/mpl/transform_view.hpp> +#include <boost/mpl/unique.hpp> +#include <boost/mpl/unpack_args.hpp> +#include <boost/mpl/upper_bound.hpp> +#include <boost/mpl/value_type.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/void.hpp> +#include <boost/mpl/zip_view.hpp> + + +int main() { } diff --git a/src/boost/libs/hana/benchmark/including/mpl11.erb.cpp b/src/boost/libs/hana/benchmark/including/mpl11.erb.cpp new file mode 100644 index 000000000..e5b9fd512 --- /dev/null +++ b/src/boost/libs/hana/benchmark/including/mpl11.erb.cpp @@ -0,0 +1,8 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/mpl11.hpp> + + +int main() { } diff --git a/src/boost/libs/hana/benchmark/make/compile.erb.json b/src/boost/libs/hana/benchmark/make/compile.erb.json new file mode 100644 index 000000000..24166876d --- /dev/null +++ b/src/boost/libs/hana/benchmark/make/compile.erb.json @@ -0,0 +1,58 @@ +<% + hana = (0...50).step(5).to_a + (50..400).step(25).to_a + fusion = (0...50).step(5).to_a + [50, 75, 100] + mpl = hana + meta = (0...50).step(5).to_a + (50..200).step(25).to_a + mpl11 = hana + std = (0...50).step(5).to_a + (50..100).step(25).to_a +%> + +{ + "title": { + "text": "Compile-time behavior of creating a sequence" + }, + "series": [ + { + "name": "hana::tuple", + "data": <%= time_compilation('compile.hana.tuple.erb.cpp', hana) %> + }, { + "name": "hana::basic_tuple", + "data": <%= time_compilation('compile.hana.basic_tuple.erb.cpp', hana) %> + }, { + "name": "std::array", + "data": <%= time_compilation('compile.std.array.erb.cpp', hana) %> + } + + , { + "name": "std::tuple", + "data": <%= time_compilation('compile.std.tuple.erb.cpp', std) %> + } + + <% if cmake_bool("@Boost_FOUND@") %> + , { + "name": "fusion::vector", + "data": <%= time_compilation('compile.fusion.vector.erb.cpp', fusion) %> + }, { + "name": "fusion::list", + "data": <%= time_compilation('compile.fusion.list.erb.cpp', fusion) %> + }, { + "name": "mpl::vector", + "data": <%= time_compilation('compile.mpl.vector.erb.cpp', mpl) %> + } + <% end %> + + <% if cmake_bool("@Meta_FOUND@") %> + , { + "name": "meta::list", + "data": <%= time_compilation('compile.meta.list.erb.cpp', meta) %> + } + <% end %> + + <% if cmake_bool("@MPL11_FOUND@") %> + , { + "name": "mpl11::list", + "data": <%= time_compilation('compile.mpl11.list.erb.cpp', mpl11) %> + } + <% end %> + ] +} diff --git a/src/boost/libs/hana/benchmark/make/compile.fusion.list.erb.cpp b/src/boost/libs/hana/benchmark/make/compile.fusion.list.erb.cpp new file mode 100644 index 000000000..7274375a8 --- /dev/null +++ b/src/boost/libs/hana/benchmark/make/compile.fusion.list.erb.cpp @@ -0,0 +1,15 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/fusion/include/make_list.hpp> +#include <boost/fusion/include/push_back.hpp> + + +template <int i> +struct x { }; + +int main() { + auto xs = <%= fusion_list((1..input_size).map { |n| "x<#{n}>{}" }) %>; + (void)xs; +} diff --git a/src/boost/libs/hana/benchmark/make/compile.fusion.vector.erb.cpp b/src/boost/libs/hana/benchmark/make/compile.fusion.vector.erb.cpp new file mode 100644 index 000000000..fd3794b34 --- /dev/null +++ b/src/boost/libs/hana/benchmark/make/compile.fusion.vector.erb.cpp @@ -0,0 +1,15 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/fusion/include/make_vector.hpp> +#include <boost/fusion/include/push_back.hpp> + + +template <int i> +struct x { }; + +int main() { + auto vector = <%= fusion_vector((1..input_size).map { |n| "x<#{n}>{}" }) %>; + (void)vector; +} diff --git a/src/boost/libs/hana/benchmark/make/compile.hana.basic_tuple.erb.cpp b/src/boost/libs/hana/benchmark/make/compile.hana.basic_tuple.erb.cpp new file mode 100644 index 000000000..a04016a4c --- /dev/null +++ b/src/boost/libs/hana/benchmark/make/compile.hana.basic_tuple.erb.cpp @@ -0,0 +1,16 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/basic_tuple.hpp> + + +template <int i> +struct x { }; + +int main() { + constexpr auto tuple = boost::hana::make_basic_tuple( + <%= (1..input_size).map { |n| "x<#{n}>{}" }.join(', ') %> + ); + (void)tuple; +} diff --git a/src/boost/libs/hana/benchmark/make/compile.hana.tuple.erb.cpp b/src/boost/libs/hana/benchmark/make/compile.hana.tuple.erb.cpp new file mode 100644 index 000000000..34ce368e3 --- /dev/null +++ b/src/boost/libs/hana/benchmark/make/compile.hana.tuple.erb.cpp @@ -0,0 +1,16 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/tuple.hpp> + + +template <int i> +struct x { }; + +int main() { + constexpr auto tuple = boost::hana::make_tuple( + <%= (1..input_size).map { |n| "x<#{n}>{}" }.join(', ') %> + ); + (void)tuple; +} diff --git a/src/boost/libs/hana/benchmark/make/compile.meta.list.erb.cpp b/src/boost/libs/hana/benchmark/make/compile.meta.list.erb.cpp new file mode 100644 index 000000000..f90fef99b --- /dev/null +++ b/src/boost/libs/hana/benchmark/make/compile.meta.list.erb.cpp @@ -0,0 +1,17 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <meta/meta.hpp> + + +template <int> +struct x; + +using list = meta::list< + <%= (1..input_size).map { |i| "x<#{i}>" }.join(', ') %> +>; + +int main() { + +} diff --git a/src/boost/libs/hana/benchmark/make/compile.mpl.vector.erb.cpp b/src/boost/libs/hana/benchmark/make/compile.mpl.vector.erb.cpp new file mode 100644 index 000000000..4b7d94c53 --- /dev/null +++ b/src/boost/libs/hana/benchmark/make/compile.mpl.vector.erb.cpp @@ -0,0 +1,14 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/mpl/push_back.hpp> +#include <boost/mpl/vector.hpp> + + +template <int i> +struct t { }; + +using vector = <%= mpl_vector((1..input_size).to_a.map { |n| "t<#{n}>" }) %>; + +int main() { } diff --git a/src/boost/libs/hana/benchmark/make/compile.mpl11.list.erb.cpp b/src/boost/libs/hana/benchmark/make/compile.mpl11.list.erb.cpp new file mode 100644 index 000000000..79d0c697d --- /dev/null +++ b/src/boost/libs/hana/benchmark/make/compile.mpl11.list.erb.cpp @@ -0,0 +1,17 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/mpl11/list.hpp> + + +template <int> +struct x; + +using list = boost::mpl11::list< + <%= (1..input_size).map { |i| "x<#{i}>" }.join(', ') %> +>; + +int main() { + +} diff --git a/src/boost/libs/hana/benchmark/make/compile.std.array.erb.cpp b/src/boost/libs/hana/benchmark/make/compile.std.array.erb.cpp new file mode 100644 index 000000000..792ec4848 --- /dev/null +++ b/src/boost/libs/hana/benchmark/make/compile.std.array.erb.cpp @@ -0,0 +1,16 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <array> + + +template <int i> +struct x { }; + +int main() { + constexpr std::array<int, <%= input_size %>> array = {{ + <%= (1..input_size).to_a.join(', ') %> + }}; + (void)array; +} diff --git a/src/boost/libs/hana/benchmark/make/compile.std.tuple.erb.cpp b/src/boost/libs/hana/benchmark/make/compile.std.tuple.erb.cpp new file mode 100644 index 000000000..11fc7cd85 --- /dev/null +++ b/src/boost/libs/hana/benchmark/make/compile.std.tuple.erb.cpp @@ -0,0 +1,16 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <tuple> + + +template <int i> +struct x { }; + +int main() { + constexpr auto tuple = std::make_tuple( + <%= (1..input_size).map { |n| "x<#{n}>{}" }.join(', ') %> + ); + (void)tuple; +} diff --git a/src/boost/libs/hana/benchmark/measure.hpp b/src/boost/libs/hana/benchmark/measure.hpp new file mode 100644 index 000000000..a477fefcf --- /dev/null +++ b/src/boost/libs/hana/benchmark/measure.hpp @@ -0,0 +1,29 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_HANA_BENCHMARK_MEASURE_HPP +#define BOOST_HANA_BENCHMARK_MEASURE_HPP + +#include <chrono> +#include <iostream> + + +namespace boost { namespace hana { namespace benchmark { + auto measure = [](auto f) { + constexpr auto repetitions = 500ull; + auto start = std::chrono::steady_clock::now(); + for (auto i = repetitions; i > 0; --i) { + f(); + } + auto stop = std::chrono::steady_clock::now(); + + auto time = std::chrono::duration_cast<std::chrono::duration<float>>( + (stop - start) / repetitions + ); + std::cout << std::fixed; + std::cout << "[execution time: " << time.count() << "]" << std::endl; + }; +}}} + +#endif diff --git a/src/boost/libs/hana/benchmark/measure.in.rb b/src/boost/libs/hana/benchmark/measure.in.rb new file mode 100755 index 000000000..65e2a98b4 --- /dev/null +++ b/src/boost/libs/hana/benchmark/measure.in.rb @@ -0,0 +1,161 @@ +#!/usr/bin/env ruby +# +# Copyright Louis Dionne 2013-2017 +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +# +# +# When called as a program, this script runs the command line given in +# arguments and returns the total time. This is similar to the `time` +# command from Bash. +# +# This file can also be required as a Ruby module to gain access to the +# methods defined below. +# +# NOTE: +# This file must not be used as-is. It must be processed by CMake first. + +require 'benchmark' +require 'open3' +require 'pathname' +require 'ruby-progressbar' +require 'tilt' + + +def split_at(n, list) + before = list[0...n] || [] + after = list[n..-1] || [] + return [before, after] +end + +# types : A sequence of strings to put in the mpl::vector. +# Using this method requires including +# - <boost/mpl/vector.hpp> +# - <boost/mpl/push_back.hpp> +def mpl_vector(types) + fast, rest = split_at(20, types) + rest.inject("boost::mpl::vector#{fast.length}<#{fast.join(', ')}>") { |v, t| + "boost::mpl::push_back<#{v}, #{t}>::type" + } +end + +# types : A sequence of strings to put in the mpl::list. +# Using this method requires including +# - <boost/mpl/list.hpp> +# - <boost/mpl/push_front.hpp> +def mpl_list(types) + prefix, fast = split_at([types.length - 20, 0].max, types) + prefix.reverse.inject("boost::mpl::list#{fast.length}<#{fast.join(', ')}>") { |l, t| + "boost::mpl::push_front<#{l}, #{t}>::type" + } +end + +# values : A sequence of strings representing values to put in the fusion::vector. +# Using this method requires including +# - <boost/fusion/include/make_vector.hpp> +# - <boost/fusion/include/push_back.hpp> +def fusion_vector(values) + fast, rest = split_at(10, values) + rest.inject("boost::fusion::make_vector(#{fast.join(', ')})") { |xs, v| + "boost::fusion::push_back(#{xs}, #{v})" + } +end + +# values : A sequence of strings representing values to put in the fusion::list. +# Using this method requires including +# - <boost/fusion/include/make_list.hpp> +# - <boost/fusion/include/push_back.hpp> +def fusion_list(values) + fast, rest = split_at(10, values) + rest.inject("boost::fusion::make_list(#{fast.join(', ')})") { |xs, v| + "boost::fusion::push_back(#{xs}, #{v})" + } +end + +# Turns a CMake-style boolean into a Ruby boolean. +def cmake_bool(b) + return true if b.is_a? String and ["true", "yes", "1"].include?(b.downcase) + return true if b.is_a? Integer and b > 0 + return false # otherwise +end + +# aspect must be one of :compilation_time, :bloat, :execution_time +def measure(aspect, template_relative, range, env = {}) + measure_file = Pathname.new("#{MEASURE_FILE}") + template = Pathname.new(template_relative).expand_path + range = range.to_a + + if ENV["BOOST_HANA_JUST_CHECK_BENCHMARKS"] && range.length >= 2 + range = [range[0], range[-1]] + end + + make = -> (target) { + command = "@CMAKE_COMMAND@ --build @CMAKE_BINARY_DIR@ --target #{target}" + stdout, stderr, status = Open3.capture3(command) + } + + progress = ProgressBar.create(format: '%p%% %t | %B |', + title: template_relative, + total: range.size, + output: STDERR) + range.map do |n| + # Evaluate the ERB template with the given environment, and save + # the result in the `measure.cpp` file. + code = Tilt::ERBTemplate.new(template).render(nil, input_size: n, env: env) + measure_file.write(code) + + # Compile the file and get timing statistics. The timing statistics + # are output to stdout when we compile the file because of the way + # the `compile.benchmark.measure` CMake target is setup. + stdout, stderr, status = make["#{MEASURE_TARGET}"] + raise "compilation error: #{stdout}\n\n#{stderr}\n\n#{code}" if not status.success? + ctime = stdout.match(/\[compilation time: (.+)\]/i) + # Size of the generated executable in KB + size = File.size("@CMAKE_CURRENT_BINARY_DIR@/#{MEASURE_TARGET}").to_f / 1000 + + # If we didn't match anything, that's because we went too fast, CMake + # did not have the time to see the changes to the measure file and + # the target was not rebuilt. So we sleep for a bit and then retry + # this iteration. + (sleep 0.2; redo) if ctime.nil? + stat = ctime.captures[0].to_f if aspect == :compilation_time + stat = size if aspect == :bloat + + # Run the resulting program and get timing statistics. The statistics + # should be written to stdout by the `measure` function of the + # `measure.hpp` header. + if aspect == :execution_time + stdout, stderr, status = make["#{MEASURE_TARGET}.run"] + raise "runtime error: #{stderr}\n\n#{code}" if not status.success? + match = stdout.match(/\[execution time: (.+)\]/i) + if match.nil? + raise ("Could not find [execution time: ...] bit in the output. " + + "Did you use the `measure` function in the `measure.hpp` header? " + + "stdout follows:\n#{stdout}") + end + stat = match.captures[0].to_f + end + + progress.increment + [n, stat] + end +ensure + measure_file.write("") + progress.finish if progress +end + +def time_execution(erb_file, range, env = {}) + measure(:execution_time, erb_file, range, env) +end + +def time_compilation(erb_file, range, env = {}) + measure(:compilation_time, erb_file, range, env) +end + +if __FILE__ == $0 + command = ARGV.join(' ') + time = Benchmark.realtime { `#{command}` } + + puts "[command line: #{command}]" + puts "[compilation time: #{time}]" +end diff --git a/src/boost/libs/hana/benchmark/reverse/move.erb.json b/src/boost/libs/hana/benchmark/reverse/move.erb.json new file mode 100644 index 000000000..81ab5b7fe --- /dev/null +++ b/src/boost/libs/hana/benchmark/reverse/move.erb.json @@ -0,0 +1,23 @@ +<% + exec = (0..100).step(10).to_a + fusion = (0..50).step(10).to_a +%> + +{ + "title": { + "text": "Runtime performance of reverse on a moved-from container" + }, + "series": [ + { + "name": "hana::tuple", + "data": <%= time_execution('move.hana.tuple.erb.cpp', exec) %> + } + + <% if cmake_bool("@Boost_FOUND@") %> + , { + "name": "fusion::vector", + "data": <%= time_execution('move.fusion.vector.erb.cpp', fusion) %> + } + <% end %> + ] +} diff --git a/src/boost/libs/hana/benchmark/reverse/move.fusion.vector.erb.cpp b/src/boost/libs/hana/benchmark/reverse/move.fusion.vector.erb.cpp new file mode 100644 index 000000000..83c293712 --- /dev/null +++ b/src/boost/libs/hana/benchmark/reverse/move.fusion.vector.erb.cpp @@ -0,0 +1,33 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +<% if input_size > 10 %> + #define FUSION_MAX_VECTOR_SIZE <%= ((input_size + 9) / 10) * 10 %> +<% end %> + +#include <boost/fusion/include/as_vector.hpp> +#include <boost/fusion/include/make_vector.hpp> +#include <boost/fusion/include/reverse.hpp> + +#include "measure.hpp" +#include <cstdlib> +#include <string> +#include <utility> +namespace fusion = boost::fusion; +namespace hana = boost::hana; + + +int main () { + std::string s(1000, 'x'); + hana::benchmark::measure([&] { + for (int iteration = 0; iteration < 1 << 5; ++iteration) { + auto values = fusion::make_vector( + <%= input_size.times.map { 's' }.join(', ') %> + ); + + auto result = fusion::as_vector(fusion::reverse(std::move(values))); + (void)result; + } + }); +} diff --git a/src/boost/libs/hana/benchmark/reverse/move.hana.tuple.erb.cpp b/src/boost/libs/hana/benchmark/reverse/move.hana.tuple.erb.cpp new file mode 100644 index 000000000..bf27357d5 --- /dev/null +++ b/src/boost/libs/hana/benchmark/reverse/move.hana.tuple.erb.cpp @@ -0,0 +1,27 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/reverse.hpp> +#include <boost/hana/tuple.hpp> + +#include "measure.hpp" +#include <cstdlib> +#include <string> +#include <utility> +namespace hana = boost::hana; + + +int main () { + std::string s(1000, 'x'); + hana::benchmark::measure([&] { + for (int iteration = 0; iteration < 1 << 5; ++iteration) { + auto values = hana::make_tuple( + <%= input_size.times.map { 's' }.join(', ') %> + ); + + auto result = hana::reverse(std::move(values)); + (void)result; + } + }); +} diff --git a/src/boost/libs/hana/benchmark/reverse/nomove.erb.json b/src/boost/libs/hana/benchmark/reverse/nomove.erb.json new file mode 100644 index 000000000..b9d39bd85 --- /dev/null +++ b/src/boost/libs/hana/benchmark/reverse/nomove.erb.json @@ -0,0 +1,23 @@ +<% + exec = (0..100).step(10).to_a + fusion = (0..50).step(10).to_a +%> + +{ + "title": { + "text": "Runtime performance of reverse on a normal container" + }, + "series": [ + { + "name": "hana::tuple", + "data": <%= time_execution('nomove.hana.tuple.erb.cpp', exec) %> + } + + <% if cmake_bool("@Boost_FOUND@") %> + , { + "name": "fusion::vector", + "data": <%= time_execution('nomove.fusion.vector.erb.cpp', fusion) %> + } + <% end %> + ] +} diff --git a/src/boost/libs/hana/benchmark/reverse/nomove.fusion.vector.erb.cpp b/src/boost/libs/hana/benchmark/reverse/nomove.fusion.vector.erb.cpp new file mode 100644 index 000000000..cbb4b07d2 --- /dev/null +++ b/src/boost/libs/hana/benchmark/reverse/nomove.fusion.vector.erb.cpp @@ -0,0 +1,33 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +<% if input_size > 10 %> + #define FUSION_MAX_VECTOR_SIZE <%= ((input_size + 9) / 10) * 10 %> +<% end %> + +#include <boost/fusion/include/as_vector.hpp> +#include <boost/fusion/include/make_vector.hpp> +#include <boost/fusion/include/reverse.hpp> + +#include "measure.hpp" +#include <cstdlib> +#include <string> +#include <utility> +namespace fusion = boost::fusion; +namespace hana = boost::hana; + + +int main () { + std::string s(1000, 'x'); + hana::benchmark::measure([&] { + for (int iteration = 0; iteration < 1 << 5; ++iteration) { + auto values = fusion::make_vector( + <%= input_size.times.map { 's' }.join(', ') %> + ); + + auto result = fusion::as_vector(fusion::reverse(values)); + (void)result; + } + }); +} diff --git a/src/boost/libs/hana/benchmark/reverse/nomove.hana.tuple.erb.cpp b/src/boost/libs/hana/benchmark/reverse/nomove.hana.tuple.erb.cpp new file mode 100644 index 000000000..913061e3d --- /dev/null +++ b/src/boost/libs/hana/benchmark/reverse/nomove.hana.tuple.erb.cpp @@ -0,0 +1,27 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/reverse.hpp> +#include <boost/hana/tuple.hpp> + +#include "measure.hpp" +#include <cstdlib> +#include <string> +#include <utility> +namespace hana = boost::hana; + + +int main () { + std::string s(1000, 'x'); + hana::benchmark::measure([&] { + for (int iteration = 0; iteration < 1 << 5; ++iteration) { + auto values = hana::make_tuple( + <%= input_size.times.map { 's' }.join(', ') %> + ); + + auto result = hana::reverse(values); + (void)result; + } + }); +} diff --git a/src/boost/libs/hana/benchmark/sort/compile.erb.json b/src/boost/libs/hana/benchmark/sort/compile.erb.json new file mode 100644 index 000000000..1a13543bc --- /dev/null +++ b/src/boost/libs/hana/benchmark/sort/compile.erb.json @@ -0,0 +1,31 @@ +<% + hana = [0, 1, 2, 5, 10, 20, 50, 100] +%> + +{ + "title": { + "text": "Compile-time behavior of sort" + }, + "series": [ + { + "name": "hana::tuple::sorted", + "data": <%= time_compilation('compile.hana.tuple.sorted.erb.cpp', hana) %> + }, + { + "name": "hana::tuple::reversed", + "data": <%= time_compilation('compile.hana.tuple.reversed.erb.cpp', hana) %> + }, + { + "name": "hana::tuple::rand", + "data": <%= time_compilation('compile.hana.tuple.rand.erb.cpp', hana) %> + }, + { + "name": "hana::tuple::sorted_but_first", + "data": <%= time_compilation('compile.hana.tuple.sorted_but_first.erb.cpp', hana) %> + }, + { + "name": "hana::tuple::sorted_but_last", + "data": <%= time_compilation('compile.hana.tuple.sorted_but_last.erb.cpp', hana) %> + } + ] +} diff --git a/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.rand.erb.cpp b/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.rand.erb.cpp new file mode 100644 index 000000000..771a1ffaf --- /dev/null +++ b/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.rand.erb.cpp @@ -0,0 +1,14 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/tuple.hpp> +#include <boost/hana/sort.hpp> + +int main() { + constexpr auto tuple = boost::hana::make_tuple( + <%= (1..input_size).to_a.shuffle.map { |n| "boost::hana::int_c<#{n}>" }.join(', ') %> + ); + constexpr auto result = boost::hana::sort(tuple); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.reversed.erb.cpp b/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.reversed.erb.cpp new file mode 100644 index 000000000..6fc85758f --- /dev/null +++ b/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.reversed.erb.cpp @@ -0,0 +1,14 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/tuple.hpp> +#include <boost/hana/sort.hpp> + +int main() { + constexpr auto tuple = boost::hana::make_tuple( + <%= (1..input_size).to_a.reverse.map { |n| "boost::hana::int_c<#{n}>" }.join(', ') %> + ); + constexpr auto result = boost::hana::sort(tuple); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.sorted.erb.cpp b/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.sorted.erb.cpp new file mode 100644 index 000000000..c48becf05 --- /dev/null +++ b/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.sorted.erb.cpp @@ -0,0 +1,14 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/tuple.hpp> +#include <boost/hana/sort.hpp> + +int main() { + constexpr auto tuple = boost::hana::make_tuple( + <%= (1..input_size).map { |n| "boost::hana::int_c<#{n}>" }.join(', ') %> + ); + constexpr auto result = boost::hana::sort(tuple); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.sorted_but_first.erb.cpp b/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.sorted_but_first.erb.cpp new file mode 100644 index 000000000..14795621f --- /dev/null +++ b/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.sorted_but_first.erb.cpp @@ -0,0 +1,14 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/tuple.hpp> +#include <boost/hana/sort.hpp> + +int main() { + constexpr auto tuple = boost::hana::make_tuple( + <%= ([input_size+1] + (1..input_size).to_a).map { |n| "boost::hana::int_c<#{n}>" }.join(', ') %> + ); + constexpr auto result = boost::hana::sort(tuple); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.sorted_but_last.erb.cpp b/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.sorted_but_last.erb.cpp new file mode 100644 index 000000000..5ed14ab7c --- /dev/null +++ b/src/boost/libs/hana/benchmark/sort/compile.hana.tuple.sorted_but_last.erb.cpp @@ -0,0 +1,14 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/tuple.hpp> +#include <boost/hana/sort.hpp> + +int main() { + constexpr auto tuple = boost::hana::make_tuple( + <%= ((1..input_size).to_a + [0]).map { |n| "boost::hana::int_c<#{n}>" }.join(', ') %> + ); + constexpr auto result = boost::hana::sort(tuple); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/transform/bloat.erb.json b/src/boost/libs/hana/benchmark/transform/bloat.erb.json new file mode 100644 index 000000000..62cbdd7ab --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/bloat.erb.json @@ -0,0 +1,42 @@ +<% + exec = (0..100).step(10).to_a + fusion = (0..50).step(10).to_a +%> + +{ + "title": { + "text": "Executable size for transform" + }, + "yAxis": { + "title": { + "text": "Executable size (kb)" + }, + "floor": 0 + }, + "tooltip": { + "valueSuffix": "kb" + }, + "series": [ + { + "name": "hana::tuple", + "data": <%= measure(:bloat, 'execute.hana.tuple.erb.cpp', exec) %> + } + + , { + "name": "std::array", + "data": <%= measure(:bloat, 'execute.std.array.erb.cpp', exec) %> + } + + , { + "name": "std::vector", + "data": <%= measure(:bloat, 'execute.std.vector.erb.cpp', exec) %> + } + + <% if cmake_bool("@Boost_FOUND@") %> + , { + "name": "fusion::vector", + "data": <%= measure(:bloat, 'execute.fusion.vector.erb.cpp', fusion) %> + } + <% end %> + ] +}
\ No newline at end of file diff --git a/src/boost/libs/hana/benchmark/transform/compile.erb.json b/src/boost/libs/hana/benchmark/transform/compile.erb.json new file mode 100644 index 000000000..9036ab49c --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/compile.erb.json @@ -0,0 +1,49 @@ +<% + hana = (0...50).step(5).to_a + (50..400).step(25).to_a + fusion = (0..50).step(5) + mpl = hana + meta = hana + mpl11 = hana +%> + +{ + "title": { + "text": "Compile-time behavior of transform" + }, + "series": [ + { + "name": "hana::tuple", + "data": <%= time_compilation('compile.hana.tuple.erb.cpp', hana) %> + }, { + "name": "hana::types", + "data": <%= time_compilation('compile.hana.types.erb.cpp', hana) %> + } + + <% if cmake_bool("@Boost_FOUND@") %> + , { + "name": "mpl::vector", + "data": <%= time_compilation('compile.mpl.vector.erb.cpp', mpl) %> + }, { + "name": "fusion::vector", + "data": <%= time_compilation('compile.fusion.vector.erb.cpp', fusion) %> + }, { + "name": "fusion::list", + "data": <%= time_compilation('compile.fusion.list.erb.cpp', fusion) %> + } + <% end %> + + <% if cmake_bool("@Meta_FOUND@") %> + , { + "name": "meta::list", + "data": <%= time_compilation('compile.meta.list.erb.cpp', meta) %> + } + <% end %> + + <% if cmake_bool("@MPL11_FOUND@") %> + , { + "name": "mpl11::list", + "data": <%= time_compilation('compile.mpl11.list.erb.cpp', mpl11) %> + } + <% end %> + ] +} diff --git a/src/boost/libs/hana/benchmark/transform/compile.fusion.list.erb.cpp b/src/boost/libs/hana/benchmark/transform/compile.fusion.list.erb.cpp new file mode 100644 index 000000000..4ced955d5 --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/compile.fusion.list.erb.cpp @@ -0,0 +1,30 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +<% if input_size > 10 %> + #define FUSION_MAX_LIST_SIZE <%= ((input_size + 9) / 10) * 10 %> +<% end %> + +#include <boost/fusion/include/as_list.hpp> +#include <boost/fusion/include/make_list.hpp> +#include <boost/fusion/include/transform.hpp> +namespace fusion = boost::fusion; + + +struct f { + template <typename X> + constexpr X operator()(X x) const { return x; } +}; + +template <int i> +struct x { }; + +int main() { + auto xs = fusion::make_list( + <%= (1..input_size).map { |n| "x<#{n}>{}" }.join(', ') %> + ); + + auto result = fusion::as_list(fusion::transform(xs, f{})); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/transform/compile.fusion.vector.erb.cpp b/src/boost/libs/hana/benchmark/transform/compile.fusion.vector.erb.cpp new file mode 100644 index 000000000..687e7b510 --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/compile.fusion.vector.erb.cpp @@ -0,0 +1,30 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +<% if input_size > 10 %> + #define FUSION_MAX_VECTOR_SIZE <%= ((input_size + 9) / 10) * 10 %> +<% end %> + +#include <boost/fusion/include/as_vector.hpp> +#include <boost/fusion/include/make_vector.hpp> +#include <boost/fusion/include/transform.hpp> +namespace fusion = boost::fusion; + + +struct f { + template <typename X> + constexpr X operator()(X x) const { return x; } +}; + +template <int i> +struct x { }; + +int main() { + auto xs = fusion::make_vector( + <%= (1..input_size).map { |n| "x<#{n}>{}" }.join(', ') %> + ); + + auto result = fusion::as_vector(fusion::transform(xs, f{})); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/transform/compile.hana.tuple.erb.cpp b/src/boost/libs/hana/benchmark/transform/compile.hana.tuple.erb.cpp new file mode 100644 index 000000000..0d3c8951d --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/compile.hana.tuple.erb.cpp @@ -0,0 +1,23 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/transform.hpp> +#include <boost/hana/tuple.hpp> + + +struct f { + template <typename X> + constexpr X operator()(X x) const { return x; } +}; + +template <int i> +struct x { }; + +int main() { + constexpr auto tuple = boost::hana::make_tuple( + <%= (1..input_size).map { |n| "x<#{n}>{}" }.join(', ') %> + ); + constexpr auto result = boost::hana::transform(tuple, f{}); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/transform/compile.hana.types.erb.cpp b/src/boost/libs/hana/benchmark/transform/compile.hana.types.erb.cpp new file mode 100644 index 000000000..0ad755699 --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/compile.hana.types.erb.cpp @@ -0,0 +1,26 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include <boost/hana/experimental/types.hpp> +#include <boost/hana/transform.hpp> +#include <boost/hana/type.hpp> +namespace hana = boost::hana; + + +template <typename> +struct f { struct type; }; + +template <int> struct x; + + +int main() { + constexpr auto types = hana::experimental::types< + <%= (1..input_size).map { |i| "x<#{i}>" }.join(', ') %> + >{}; + + constexpr auto result = hana::transform(types, hana::metafunction<f>); + (void)result; +} diff --git a/src/boost/libs/hana/benchmark/transform/compile.meta.list.erb.cpp b/src/boost/libs/hana/benchmark/transform/compile.meta.list.erb.cpp new file mode 100644 index 000000000..1341cccb4 --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/compile.meta.list.erb.cpp @@ -0,0 +1,23 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <meta/meta.hpp> + + +struct f { + template <typename> + struct apply; +}; + +template <int> struct x; + +using list = meta::list< + <%= (1..input_size).map { |i| "x<#{i}>" }.join(', ') %> +>; + +using result = meta::transform<list, f>; + +int main() { + +} diff --git a/src/boost/libs/hana/benchmark/transform/compile.mpl.vector.erb.cpp b/src/boost/libs/hana/benchmark/transform/compile.mpl.vector.erb.cpp new file mode 100644 index 000000000..a7bdc72d8 --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/compile.mpl.vector.erb.cpp @@ -0,0 +1,22 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/mpl/push_back.hpp> +#include <boost/mpl/quote.hpp> +#include <boost/mpl/transform.hpp> +#include <boost/mpl/vector.hpp> + + +template <typename X> +struct f { using type = X; }; + +template <int i> +struct t { }; + +using vector = <%= mpl_vector((1..input_size).to_a.map { |n| "t<#{n}>" }) %>; + +using result = boost::mpl::transform<vector, boost::mpl::quote1<f>>::type; + + +int main() { } diff --git a/src/boost/libs/hana/benchmark/transform/compile.mpl11.list.erb.cpp b/src/boost/libs/hana/benchmark/transform/compile.mpl11.list.erb.cpp new file mode 100644 index 000000000..262e48bc0 --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/compile.mpl11.list.erb.cpp @@ -0,0 +1,24 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/mpl11/list.hpp> + + +struct f { + using type = f; + template <typename> + struct apply { struct type; }; +}; + +template <int> struct x { struct type; }; + +using list = boost::mpl11::list< + <%= (1..input_size).map { |i| "x<#{i}>" }.join(', ') %> +>; + +using result = boost::mpl11::fmap<f, list>::type; + +int main() { + +} diff --git a/src/boost/libs/hana/benchmark/transform/execute.erb.json b/src/boost/libs/hana/benchmark/transform/execute.erb.json new file mode 100644 index 000000000..98738317e --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/execute.erb.json @@ -0,0 +1,36 @@ +<% + exec = (0..100).step(10).to_a + fusion = (0..50).step(10).to_a +%> + +{ + "title": { + "text": "Runtime behavior of transform" + }, + "series": [ + { + "name": "hana::tuple", + "data": <%= time_execution('execute.hana.tuple.erb.cpp', exec) %> + } + + , { + "name": "std::array", + "data": <%= time_execution('execute.std.array.erb.cpp', exec) %> + } + + , { + "name": "std::vector", + "data": <%= time_execution('execute.std.vector.erb.cpp', exec) %> + } + + <% if cmake_bool("@Boost_FOUND@") %> + , { + "name": "fusion::vector", + "data": <%= time_execution('execute.fusion.vector.erb.cpp', fusion) %> + }, { + "name": "fusion::list", + "data": <%= time_execution('execute.fusion.list.erb.cpp', fusion) %> + } + <% end %> + ] +} diff --git a/src/boost/libs/hana/benchmark/transform/execute.fusion.list.erb.cpp b/src/boost/libs/hana/benchmark/transform/execute.fusion.list.erb.cpp new file mode 100644 index 000000000..5855a61da --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/execute.fusion.list.erb.cpp @@ -0,0 +1,33 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +<% if input_size > 10 %> + #define FUSION_MAX_LIST_SIZE <%= ((input_size + 9) / 10) * 10 %> +<% end %> + +#include <boost/fusion/include/as_list.hpp> +#include <boost/fusion/include/make_list.hpp> +#include <boost/fusion/include/transform.hpp> + +#include "measure.hpp" +#include <cstdlib> +namespace fusion = boost::fusion; +namespace hana = boost::hana; + + +int main () { + hana::benchmark::measure([] { + long long result = 0; + for (int iteration = 0; iteration < 1 << 10; ++iteration) { + auto values = fusion::make_list( + <%= input_size.times.map { 'std::rand()' }.join(', ') %> + ); + + auto transformed = fusion::as_list(fusion::transform(values, [&](auto t) { + return result += t; + })); + (void)transformed; + } + }); +} diff --git a/src/boost/libs/hana/benchmark/transform/execute.fusion.vector.erb.cpp b/src/boost/libs/hana/benchmark/transform/execute.fusion.vector.erb.cpp new file mode 100644 index 000000000..721a35f24 --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/execute.fusion.vector.erb.cpp @@ -0,0 +1,33 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +<% if input_size > 10 %> + #define FUSION_MAX_VECTOR_SIZE <%= ((input_size + 9) / 10) * 10 %> +<% end %> + +#include <boost/fusion/include/as_vector.hpp> +#include <boost/fusion/include/make_vector.hpp> +#include <boost/fusion/include/transform.hpp> + +#include "measure.hpp" +#include <cstdlib> +namespace fusion = boost::fusion; +namespace hana = boost::hana; + + +int main () { + hana::benchmark::measure([] { + long long result = 0; + for (int iteration = 0; iteration < 1 << 10; ++iteration) { + auto values = fusion::make_vector( + <%= input_size.times.map { 'std::rand()' }.join(', ') %> + ); + + auto transformed = fusion::as_vector(fusion::transform(values, [&](auto t) { + return result += t; + })); + (void)transformed; + } + }); +} diff --git a/src/boost/libs/hana/benchmark/transform/execute.hana.tuple.erb.cpp b/src/boost/libs/hana/benchmark/transform/execute.hana.tuple.erb.cpp new file mode 100644 index 000000000..8d58e1938 --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/execute.hana.tuple.erb.cpp @@ -0,0 +1,26 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/transform.hpp> +#include <boost/hana/tuple.hpp> + +#include "measure.hpp" +#include <cstdlib> + + +int main () { + boost::hana::benchmark::measure([] { + long long result = 0; + for (int iteration = 0; iteration < 1 << 10; ++iteration) { + auto values = boost::hana::make_tuple( + <%= input_size.times.map { 'std::rand()' }.join(', ') %> + ); + + auto transformed = boost::hana::transform(values, [&](auto t) { + return result += t; + }); + (void)transformed; + } + }); +} diff --git a/src/boost/libs/hana/benchmark/transform/execute.std.array.erb.cpp b/src/boost/libs/hana/benchmark/transform/execute.std.array.erb.cpp new file mode 100644 index 000000000..f5537be40 --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/execute.std.array.erb.cpp @@ -0,0 +1,26 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include "measure.hpp" +#include <algorithm> +#include <array> +#include <cstdlib> + + +int main () { + boost::hana::benchmark::measure([] { + long long result = 0; + for (int iteration = 0; iteration < 1 << 10; ++iteration) { + std::array<int, <%= input_size %>> values = {{ + <%= input_size.times.map { 'std::rand()' }.join(', ') %> + }}; + + std::array<long long, <%= input_size %>> results{}; + + std::transform(values.begin(), values.end(), results.begin(), [&](auto t) { + return result += t; + }); + } + }); +} diff --git a/src/boost/libs/hana/benchmark/transform/execute.std.vector.erb.cpp b/src/boost/libs/hana/benchmark/transform/execute.std.vector.erb.cpp new file mode 100644 index 000000000..5b6b11d75 --- /dev/null +++ b/src/boost/libs/hana/benchmark/transform/execute.std.vector.erb.cpp @@ -0,0 +1,27 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include "measure.hpp" +#include <algorithm> +#include <cstdlib> +#include <vector> + + +int main () { + boost::hana::benchmark::measure([] { + long long result = 0; + for (int iteration = 0; iteration < 1 << 10; ++iteration) { + std::vector<int> values = { + <%= input_size.times.map { 'std::rand()' }.join(', ') %> + }; + + std::vector<long long> results; + results.reserve(<%= input_size %>); + + std::transform(values.begin(), values.end(), results.begin(), [&](auto t) { + return result += t; + }); + } + }); +} |