From e68a3ac4d9b941f09be45687d99b47ea486b3f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Mon, 29 Sep 2025 00:44:01 +0200 Subject: [PATCH] Add reservable deque to benchmark --- bench/bench_vectors.cpp | 67 ++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/bench/bench_vectors.cpp b/bench/bench_vectors.cpp index 456222b..87fa3bc 100644 --- a/bench/bench_vectors.cpp +++ b/bench/bench_vectors.cpp @@ -36,6 +36,23 @@ #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 0 #include + +//reserve +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME reserve +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace test { +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 1 +#include + +//back_reserve +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME reserve_back +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace test { +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 1 +#include + //#pragma GCC diagnostic ignored "-Wunused-result" #if defined(BOOST_GCC) && (BOOST_GCC >= 40600) #pragma GCC diagnostic pop @@ -132,9 +149,19 @@ class MyFatInt } }; -template::value> -struct capacity_wrapper +template +struct capacity_wrapper_impl +{ + inline static typename C::size_type get_capacity(const C &) + { return 0u; } + + inline static void set_reserve(C &, typename C::size_type ) + { } +}; + + +template +struct capacity_wrapper_impl { inline static typename C::size_type get_capacity(const C &c) { return c.capacity(); } @@ -143,16 +170,26 @@ struct capacity_wrapper { c.reserve(cp); } }; -template -struct capacity_wrapper +template +struct capacity_wrapper_impl { - inline static typename C::size_type get_capacity(const C &) - { return 0u; } + inline static typename C::size_type get_capacity(const C &c) + { return c.back_capacity(); } - inline static void set_reserve(C &, typename C::size_type ) - { } + inline static void set_reserve(C &c, typename C::size_type cp) + { c.reserve_back(cp); } }; +template +struct capacity_wrapper + : capacity_wrapper_impl + < C + , bc::test::has_member_function_callable_with_reserve::value + , bc::test::has_member_function_callable_with_reserve_back::value + > +{}; + + const std::size_t RangeSize = 8; template @@ -304,6 +341,8 @@ void vector_test_template(std::size_t num_iterations, std::size_t num_elements, cpu_timer timer; const std::size_t max = num_elements/multiplier; + std::size_t capacity = 0u; + for(std::size_t r = 0; r != num_iterations; ++r){ //Unroll the loop to avoid noise from loop code int i = 0; @@ -330,13 +369,11 @@ void vector_test_template(std::size_t num_iterations, std::size_t num_elements, if (r > num_iterations/10) timer.stop(); + if(r == (num_iterations-1u)) + capacity = cpw_t::get_capacity(c); c.clear(); } - timer.stop(); - - std::size_t capacity = cpw_t::get_capacity(c); - nanosecond_type nseconds = timer.elapsed().wall; std::cout << cont_name << "->" << " ns: " @@ -379,7 +416,7 @@ void test_vectors_impl() #define RESERVE_ONLY 0 #define NORESERVE_ONLY 1 -#define RESERVE_STRATEGY NORESERVE_ONLY +//#define RESERVE_STRATEGY NORESERVE_ONLY //#define RESERVE_STRATEGY RESERVE_ONLY #ifndef RESERVE_STRATEGY @@ -407,6 +444,8 @@ void test_vectors_impl() vector_test_template< bc::devector >, Operation >(numit[i], numele[i], "devector ", bp); vector_test_template< std::deque >, Operation >(numit[i], numele[i], "std::deque ", bp); vector_test_template< bc::deque >, Operation >(numit[i], numele[i], "deque ", bp); + vector_test_template< bc::deque, + typename bc::deque_options >::type >, Operation >(numit[i], numele[i], "deque(reserv) ", bp); } std::cout << "---------------------------------\n---------------------------------\n"; }