From 08ded32473eba7b953d2d79b6bd30ea56d30efd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 6 Sep 2025 12:46:25 +0200 Subject: [PATCH] Increase range size to 8 and template the integer type to contemplate both trivial and non-trivial types. --- .gitignore | 1 + bench/bench_vectors.cpp | 122 ++++++++++++++++++++++++++-------------- doc/container.qbk | 2 + 3 files changed, 84 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index d9a49e4..d388948 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ /bench/detail/hash_table.hpp /Bin/ /include/boost/container/new_deque.hpp +/test/new_deque_test.cpp diff --git a/bench/bench_vectors.cpp b/bench/bench_vectors.cpp index 8c8a65a..7599de9 100644 --- a/bench/bench_vectors.cpp +++ b/bench/bench_vectors.cpp @@ -12,6 +12,7 @@ #include #include #include +#include "new_deque.hpp" #include #include #include @@ -93,8 +94,9 @@ struct capacity_wrapper { } }; -const std::size_t RangeSize = 5; +const std::size_t RangeSize = 8; +template struct insert_end_range { inline std::size_t capacity_multiplier() const @@ -105,11 +107,12 @@ struct insert_end_range { c.insert(c.end(), &a[0], &a[0]+RangeSize); } const char *name() const - { return "insert_end_range"; } + { return "insert_end_range(8)"; } - MyInt a[RangeSize]; + IntType a[RangeSize]; }; +template struct insert_end_repeated { inline std::size_t capacity_multiplier() const @@ -117,14 +120,15 @@ struct insert_end_repeated template inline void operator()(C &c, int i) - { c.insert(c.end(), RangeSize, MyInt(i)); } + { c.insert(c.end(), RangeSize, IntType(i)); } inline const char *name() const - { return "insert_end_repeated"; } + { return "insert_end_repeated(8)"; } - MyInt a[RangeSize]; + IntType a[RangeSize]; }; +template struct push_back { inline std::size_t capacity_multiplier() const @@ -132,12 +136,13 @@ struct push_back template inline void operator()(C &c, int i) - { c.push_back(MyInt(i)); } + { c.push_back(IntType(i)); } inline const char *name() const { return "push_back"; } }; +template struct emplace_back { inline std::size_t capacity_multiplier() const @@ -151,6 +156,7 @@ struct emplace_back { return "emplace_back"; } }; +template struct insert_near_end_repeated { inline std::size_t capacity_multiplier() const @@ -158,12 +164,13 @@ struct insert_near_end_repeated template inline void operator()(C &c, int i) - { c.insert(c.size() >= 2*RangeSize ? c.end()-2*RangeSize : c.begin(), RangeSize, MyInt(i)); } + { c.insert(c.size() >= 2*RangeSize ? c.end()-2*RangeSize : c.begin(), RangeSize, IntType(i)); } inline const char *name() const - { return "insert_near_end_repeated"; } + { return "insert_near_end_repeated(8)"; } }; +template struct insert_near_end_range { inline std::size_t capacity_multiplier() const @@ -176,11 +183,12 @@ struct insert_near_end_range } inline const char *name() const - { return "insert_near_end_range"; } + { return "insert_near_end_range(8)"; } - MyInt a[RangeSize]; + IntType a[RangeSize]; }; +template struct insert_near_end { inline std::size_t capacity_multiplier() const @@ -192,13 +200,14 @@ struct insert_near_end typedef typename C::iterator it_t; it_t it (c.end()); it -= static_cast(c.size() >= 2)*2; - c.insert(it, MyInt(i)); + c.insert(it, IntType(i)); } inline const char *name() const { return "insert_near_end"; } }; +template struct emplace_near_end { inline std::size_t capacity_multiplier() const @@ -272,7 +281,7 @@ void vector_test_template(std::size_t num_iterations, std::size_t num_elements, nanosecond_type nseconds = timer.elapsed().wall; - std::cout << cont_name << "->" << op.name() <<" ns: " + std::cout << cont_name << "->" << " ns: " << std::setw(8) << float(nseconds)/float((num_iterations-1)*num_elements) << '\t' @@ -280,8 +289,8 @@ void vector_test_template(std::size_t num_iterations, std::size_t num_elements, << std::endl; } -template -void test_vectors() +template +void test_vectors_impl() { //#define SINGLE_TEST #define SIMPLE_IT @@ -293,7 +302,11 @@ void test_vectors() #endif std::size_t numele [] = { 100000 }; #elif defined SIMPLE_IT + #ifdef NDEBUG + std::size_t numit [] = { 50 }; + #else std::size_t numit [] = { 10 }; + #endif std::size_t numele [] = { 100000 }; #else #ifdef NDEBUG @@ -304,42 +317,69 @@ void test_vectors() unsigned int numele [] = { 10000, 1000, 100, 10 }; #endif - //#define PRERESERVE_ONLY - #ifdef PRERESERVE_ONLY - #define P_INIT 1 - #else - #define P_INIT 0 - #endif - for (unsigned p = P_INIT; p != 2; ++p) { - std::cout << Operation().name() << ", prereserve: " << (p ? "1" : "0") << "\n" << std::endl; - const bool bp =p != 0; - for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){ - vector_test_template< std::vector >, Operation >(numit[i], numele[i], "std::vector ", bp); - vector_test_template< bc::vector >, Operation >(numit[i], numele[i] , "vector ", bp); - vector_test_template< bc::small_vector >, Operation >(numit[i], numele[i], "small_vector ", bp); - 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); +#define RESERVE_ONLY 0 +#define NORESERVE_ONLY 1 + +//#define RESERVE_STRATEGY NORESERVE_ONLY +#define RESERVE_STRATEGY RESERVE_ONLY + +#ifndef RESERVE_STRATEGY + #define P_INIT 0 + #define P_END 2 +#elif RESERVE_STRATEGY == PRERESERVE_ONLY + #define P_INIT 1 + #define P_END 2 +#elif RESERVE_STRATEGY == NORESERVE_ONLY + #define P_INIT 0 + #define P_END 1 +#endif + + for (unsigned p = P_INIT; p != P_END; ++p) { + std::cout << "---------------------------------\n"; + std::cout << "IntType:" << typeid(IntType).name() << " op:" << Operation().name() << ", prereserve: " << (p ? "1" : "0") << "\n"; + std::cout << "---------------------------------\n"; + const bool bp = p != 0; + const std::size_t it_count = sizeof(numele)/sizeof(numele[0]); + for(unsigned int i = 0; i < it_count; ++i){ + std::cout << "\n" << " ---- numit[i]: " << numit[i] << " numele[i] : " << numele[i] << " ---- \n"; + vector_test_template< std::vector >, Operation >(numit[i], numele[i], "std::vector ", bp); + vector_test_template< bc::vector >, Operation >(numit[i], numele[i] , "vector ", bp); + vector_test_template< bc::small_vector >, Operation >(numit[i], numele[i], "small_vector ", bp); + 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::new_deque >, Operation >(numit[i], numele[i], "new_deque ", bp); } std::cout << "---------------------------------\n---------------------------------\n"; } } -int main() +template +void test_vectors() { //end - test_vectors(); - test_vectors(); - test_vectors(); - //near end - test_vectors(); - test_vectors(); - test_vectors(); + test_vectors_impl >(); #if BOOST_CXX_VERSION >= 201103L - test_vectors(); - test_vectors(); + test_vectors_impl >(); #endif + test_vectors_impl >(); + test_vectors_impl >(); + + //near end + test_vectors_impl >(); + #if BOOST_CXX_VERSION >= 201103L + test_vectors_impl >(); + #endif + test_vectors_impl >(); + test_vectors_impl >(); +} + +int main() +{ + //test_vectors(); + test_vectors(); + return 0; } diff --git a/doc/container.qbk b/doc/container.qbk index d60f6f1..e5d6eeb 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1425,9 +1425,11 @@ use [*Boost.Container]? There are several reasons for that: * Fixed bugs/issues: * [@https://github.com/boostorg/container/pull/294 GitHub #294: ['"CMake: Add option to use header-only Boost::container"]]. + * [@https://github.com/boostorg/container/issues/300 GitHub #300: ['"Warnings when building with clang-20"]]. * [@https://github.com/boostorg/container/pull/305 GitHub #305: ['"Warnings with -Wstrict-prototypes"]]. * [@https://github.com/boostorg/container/pull/307 GitHub #307: ['"Fix all instances of MSVC warning C4146 (unsigned negation)"]]. * [@https://github.com/boostorg/container/issues/309 GitHub #309: ['"Performance regression of boost::container::static_vector introduced in boost v1.86"]]. + * [@https://github.com/boostorg/container/issues/306 GitHub #306: ['"new_allocator.hpp error: '__cpp_sized_deallocation' is not defined, evaluates to 0 [-Werror,-Wundef]"]]. * [@https://github.com/boostorg/container/issues/310 GitHub #310: ['"flat_map: Mention correct type in documentation of emplace and emplace_hint"]]. [endsect]