2020-08-10 00:16:58 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2026-06-21 21:07:55 +02:00
|
|
|
// (C) Copyright Ion Gaztanaga 2007-2026. Distributed under the Boost
|
2020-08-10 00:16:58 +02:00
|
|
|
// Software License, Version 1.0. (See accompanying file
|
|
|
|
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
//
|
|
|
|
|
// See http://www.boost.org/libs/container for documentation.
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2026-06-21 21:07:55 +02:00
|
|
|
//
|
2026-06-23 00:39:59 +02:00
|
|
|
// Shared harness for the sequence-container insertion benchmarks.
|
|
|
|
|
//
|
|
|
|
|
// Design:
|
|
|
|
|
// - Auto-scaling measurement: each timing repeats the build until a minimum
|
|
|
|
|
// wall-clock budget elapses, runs several trials and discards the slowest
|
|
|
|
|
// - Dead-store-elimination barriers: clobber()/escape() (bench_utils.hpp) wrap
|
|
|
|
|
// the measured region so the optimizer cannot delete the work.
|
|
|
|
|
// - Ratio output: every container is timed and reported as a num/den ratio
|
|
|
|
|
// against the first container the runner registers (the baseline), with a
|
|
|
|
|
// per-column geometric mean. A compact table is printed per element type and
|
|
|
|
|
// prereserve setting.
|
|
|
|
|
//
|
|
|
|
|
// A runner includes this header, implements the run_containers() customization
|
|
|
|
|
// point registering the containers it wants to compare (the FIRST one is the
|
|
|
|
|
// baseline/denominator) and calls test_vectors<int>():
|
2026-06-21 21:07:55 +02:00
|
|
|
//
|
|
|
|
|
// #include "bench_vector_common.hpp"
|
|
|
|
|
// template<class IntType, class Operation>
|
2026-06-23 00:39:59 +02:00
|
|
|
// void run_containers(runner<IntType, Operation>& r)
|
2026-06-21 21:07:55 +02:00
|
|
|
// {
|
2026-06-23 00:39:59 +02:00
|
|
|
// r.template add< std::vector<IntType> >("std::vector"); //baseline
|
|
|
|
|
// r.template add< bc::vector<IntType> >("vector");
|
2026-06-21 21:07:55 +02:00
|
|
|
// }
|
|
|
|
|
// int main(){ test_vectors<int>(); return 0; }
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#ifndef BOOST_CONTAINER_BENCH_VECTOR_COMMON_HPP
|
|
|
|
|
#define BOOST_CONTAINER_BENCH_VECTOR_COMMON_HPP
|
|
|
|
|
|
|
|
|
|
#include <boost/config.hpp>
|
|
|
|
|
#include <boost/container/detail/workaround.hpp>
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cmath>
|
2026-06-21 21:07:55 +02:00
|
|
|
#include <cstddef>
|
2026-06-23 00:39:59 +02:00
|
|
|
#include <iomanip>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
2020-08-10 00:16:58 +02:00
|
|
|
#include <typeinfo>
|
2026-06-23 00:39:59 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
2026-06-21 21:07:55 +02:00
|
|
|
#include <boost/move/detail/nsec_clock.hpp>
|
2026-06-23 10:43:34 +02:00
|
|
|
#include <boost/container/vector.hpp>
|
|
|
|
|
#include <boost/container/string.hpp>
|
2026-06-23 00:39:59 +02:00
|
|
|
#include "bench_utils.hpp" //clobber(), escape()
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2021-01-01 23:43:44 +01:00
|
|
|
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
|
2020-11-05 14:24:35 +01:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-result"
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-08-10 00:16:58 +02:00
|
|
|
//capacity
|
|
|
|
|
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME capacity
|
|
|
|
|
#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 0
|
|
|
|
|
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 0
|
|
|
|
|
#include <boost/intrusive/detail/has_member_function_callable_with.hpp>
|
|
|
|
|
|
2025-09-29 00:44:01 +02:00
|
|
|
//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 <boost/intrusive/detail/has_member_function_callable_with.hpp>
|
|
|
|
|
|
|
|
|
|
//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 <boost/intrusive/detail/has_member_function_callable_with.hpp>
|
|
|
|
|
|
2021-01-01 23:43:44 +01:00
|
|
|
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
|
2020-11-05 14:24:35 +01:00
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-08-10 00:16:58 +02:00
|
|
|
namespace bc = boost::container;
|
|
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Benchmark configuration knobs.
|
|
|
|
|
//
|
|
|
|
|
// Container sizes are swept as 10^min_size_exp .. 10^max_size_exp. The defaults
|
|
|
|
|
// follow the same NDEBUG / LONG_BENCH profile idea used by bench_node_cont.hpp.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: fixed-capacity containers (e.g. static_vector) are sized with
|
|
|
|
|
// bench_max_numele, which is derived from max_size_exp, so the two stay in sync.
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
struct bench_vector_defaults
|
|
|
|
|
{
|
|
|
|
|
typedef boost::move_detail::nanosecond_type nanosecond_type;
|
|
|
|
|
|
|
|
|
|
#if defined(LONG_BENCH)
|
|
|
|
|
static const std::size_t min_size_exp = 2;
|
2026-06-23 10:43:34 +02:00
|
|
|
static const std::size_t max_size_exp = 5;
|
|
|
|
|
static const std::size_t num_trials = 6;
|
2026-06-23 00:39:59 +02:00
|
|
|
//50 ms per trial
|
|
|
|
|
static const nanosecond_type min_time_per_trial = nanosecond_type(50) * 1000000;
|
|
|
|
|
#else
|
2026-06-23 10:43:34 +02:00
|
|
|
static const std::size_t min_size_exp = 3;
|
2026-06-23 00:39:59 +02:00
|
|
|
static const std::size_t max_size_exp = 3;
|
|
|
|
|
static const std::size_t num_trials = 1;
|
|
|
|
|
static const nanosecond_type min_time_per_trial = 0;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//Which prereserve passes to run (replaces the old RESERVE_STRATEGY macros).
|
|
|
|
|
static const bool run_noreserve = true;
|
|
|
|
|
static const bool run_prereserve = true;
|
|
|
|
|
|
|
|
|
|
//Range length used by the *_range / *_repeated operations, expressed as a
|
|
|
|
|
//divisor of the final container size: range = max(1, n / range_divisor).
|
|
|
|
|
//A divisor of 100 means each range insertion is 1% of the final size.
|
|
|
|
|
static const std::size_t range_divisor = 100;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Range length for a given final size n, following the bench_vector_defaults
|
|
|
|
|
//policy (fixed range_size, or proportional via range_divisor).
|
|
|
|
|
inline std::size_t bench_range_size(std::size_t n)
|
|
|
|
|
{
|
|
|
|
|
//Guard against a zero divisor (avoids UB and the compile-time div-by-zero
|
|
|
|
|
//diagnostic should the config ever be set to 0).
|
|
|
|
|
const std::size_t div =
|
|
|
|
|
bench_vector_defaults::range_divisor ? bench_vector_defaults::range_divisor : std::size_t(1);
|
|
|
|
|
const std::size_t r = n / div;
|
|
|
|
|
return r ? r : std::size_t(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Human-readable description of the range policy, e.g. "n/100".
|
2026-06-23 10:43:34 +02:00
|
|
|
inline bc::string bench_range_label()
|
2026-06-23 00:39:59 +02:00
|
|
|
{
|
|
|
|
|
std::ostringstream o;
|
|
|
|
|
o << "n/" << bench_vector_defaults::range_divisor;
|
2026-06-23 10:43:34 +02:00
|
|
|
return bc::string(o.str().c_str());
|
2026-06-23 00:39:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Runtime 10^e (e is small here), used where e is only known at run time.
|
|
|
|
|
inline BOOST_CONSTEXPR std::size_t bench_pow10(std::size_t e)
|
|
|
|
|
{ return e ? std::size_t(10) * bench_pow10(e - 1u) : std::size_t(1); }
|
|
|
|
|
|
|
|
|
|
//Compile-time 10^E as an integral constant expression. Unlike bench_pow10
|
|
|
|
|
//above this works in C++03 too (where a function call is not a constant
|
|
|
|
|
//expression), so bench_max_numele is usable as static_vector's capacity.
|
|
|
|
|
template<std::size_t E>
|
|
|
|
|
struct bench_pow10_c
|
|
|
|
|
{ static const std::size_t value = std::size_t(10) * bench_pow10_c<E - 1u>::value; };
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
struct bench_pow10_c<0u>
|
|
|
|
|
{ static const std::size_t value = std::size_t(1); };
|
|
|
|
|
|
2026-06-21 21:07:55 +02:00
|
|
|
//Largest element count exercised by the harness. Fixed-capacity containers
|
|
|
|
|
//(e.g. static_vector) must be sized at least this big.
|
2026-06-23 00:39:59 +02:00
|
|
|
BOOST_CONSTEXPR_OR_CONST std::size_t bench_max_numele =
|
|
|
|
|
bench_pow10_c<bench_vector_defaults::max_size_exp>::value;
|
2025-09-20 10:48:50 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// reserve()/capacity() abstraction (some containers offer reserve_back instead,
|
|
|
|
|
// some offer neither).
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2026-02-25 23:13:00 +01:00
|
|
|
template<class C, bool Capacity, bool BackCapacity>
|
2025-09-29 00:44:01 +02:00
|
|
|
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<class C>
|
|
|
|
|
struct capacity_wrapper_impl<C, true, false>
|
2020-08-10 00:16:58 +02:00
|
|
|
{
|
2023-05-10 22:15:00 +02:00
|
|
|
inline static typename C::size_type get_capacity(const C &c)
|
2020-08-10 00:16:58 +02:00
|
|
|
{ return c.capacity(); }
|
|
|
|
|
|
2023-05-10 22:15:00 +02:00
|
|
|
inline static void set_reserve(C &c, typename C::size_type cp)
|
2020-08-10 00:16:58 +02:00
|
|
|
{ c.reserve(cp); }
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-29 00:44:01 +02:00
|
|
|
template<class C, bool Capacity>
|
|
|
|
|
struct capacity_wrapper_impl<C, Capacity, true>
|
2020-08-10 00:16:58 +02:00
|
|
|
{
|
2025-09-29 00:44:01 +02:00
|
|
|
inline static typename C::size_type get_capacity(const C &c)
|
|
|
|
|
{ return c.back_capacity(); }
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2025-09-29 00:44:01 +02:00
|
|
|
inline static void set_reserve(C &c, typename C::size_type cp)
|
|
|
|
|
{ c.reserve_back(cp); }
|
2020-08-10 00:16:58 +02:00
|
|
|
};
|
|
|
|
|
|
2025-09-29 00:44:01 +02:00
|
|
|
template<class C>
|
|
|
|
|
struct capacity_wrapper
|
|
|
|
|
: capacity_wrapper_impl
|
|
|
|
|
< C
|
|
|
|
|
, bc::test::has_member_function_callable_with_reserve<C, std::size_t>::value
|
|
|
|
|
, bc::test::has_member_function_callable_with_reserve_back<C, std::size_t>::value
|
|
|
|
|
>
|
|
|
|
|
{};
|
|
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Operations. Each functor exposes a uniform interface:
|
|
|
|
|
// explicit Op(std::size_t n): n is the final container size; range-based ops
|
|
|
|
|
// use it to size their range (see bench_range_size).
|
|
|
|
|
// capacity_multiplier(): elements inserted per operator() call.
|
|
|
|
|
// operator()(C&, int): one insertion step.
|
|
|
|
|
// name(): short label for the report.
|
|
|
|
|
//
|
|
|
|
|
// The range-based operations keep a runtime buffer (their range length is no
|
|
|
|
|
// longer a compile-time constant), so they are constructed once per measured
|
|
|
|
|
// build, outside the timed region.
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2025-09-06 12:46:25 +02:00
|
|
|
template <class IntType>
|
2020-08-10 00:16:58 +02:00
|
|
|
struct insert_end_range
|
|
|
|
|
{
|
2026-06-23 00:39:59 +02:00
|
|
|
explicit insert_end_range(std::size_t n)
|
|
|
|
|
: range_(bench_range_size(n)), a_(range_, IntType(0))
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
std::size_t capacity_multiplier() const
|
|
|
|
|
{ return range_; }
|
2020-08-10 00:16:58 +02:00
|
|
|
|
|
|
|
|
template<class C>
|
2026-02-25 23:13:00 +01:00
|
|
|
BOOST_CONTAINER_FORCEINLINE void operator()(C &c, int)
|
2026-06-23 00:39:59 +02:00
|
|
|
{ c.insert(c.end(), &a_[0], &a_[0]+range_); }
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::string name() const
|
2026-06-23 00:39:59 +02:00
|
|
|
{ return "insert_end_range(" + bench_range_label() + ")"; }
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
std::size_t range_;
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::vector<IntType> a_;
|
2020-08-10 00:16:58 +02:00
|
|
|
};
|
|
|
|
|
|
2025-09-06 12:46:25 +02:00
|
|
|
template <class IntType>
|
2020-08-10 00:16:58 +02:00
|
|
|
struct insert_end_repeated
|
|
|
|
|
{
|
2026-06-23 00:39:59 +02:00
|
|
|
explicit insert_end_repeated(std::size_t n)
|
|
|
|
|
: range_(bench_range_size(n))
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
std::size_t capacity_multiplier() const
|
|
|
|
|
{ return range_; }
|
2020-08-10 00:16:58 +02:00
|
|
|
|
|
|
|
|
template<class C>
|
2026-02-25 23:13:00 +01:00
|
|
|
BOOST_CONTAINER_FORCEINLINE void operator()(C &c, int i)
|
2026-06-23 00:39:59 +02:00
|
|
|
{ c.insert(c.end(), range_, IntType(i)); }
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::string name() const
|
2026-06-23 00:39:59 +02:00
|
|
|
{ return "insert_end_repeated(" + bench_range_label() + ")"; }
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
std::size_t range_;
|
2020-08-10 00:16:58 +02:00
|
|
|
};
|
|
|
|
|
|
2025-09-06 12:46:25 +02:00
|
|
|
template <class IntType>
|
2020-08-10 00:16:58 +02:00
|
|
|
struct push_back
|
|
|
|
|
{
|
2026-06-23 00:39:59 +02:00
|
|
|
explicit push_back(std::size_t) {}
|
|
|
|
|
|
|
|
|
|
std::size_t capacity_multiplier() const
|
2020-08-10 00:16:58 +02:00
|
|
|
{ return 1; }
|
|
|
|
|
|
|
|
|
|
template<class C>
|
2026-02-25 23:13:00 +01:00
|
|
|
BOOST_CONTAINER_FORCEINLINE void operator()(C &c, int i)
|
2025-09-06 12:46:25 +02:00
|
|
|
{ c.push_back(IntType(i)); }
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::string name() const
|
2020-08-10 00:16:58 +02:00
|
|
|
{ return "push_back"; }
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-06 12:46:25 +02:00
|
|
|
template <class IntType>
|
2022-08-24 14:40:47 +02:00
|
|
|
struct emplace_back
|
|
|
|
|
{
|
2026-06-23 00:39:59 +02:00
|
|
|
explicit emplace_back(std::size_t) {}
|
|
|
|
|
|
|
|
|
|
std::size_t capacity_multiplier() const
|
2022-08-24 14:40:47 +02:00
|
|
|
{ return 1; }
|
|
|
|
|
|
|
|
|
|
template<class C>
|
2026-02-25 23:13:00 +01:00
|
|
|
BOOST_CONTAINER_FORCEINLINE void operator()(C &c, int i)
|
2025-09-20 10:48:50 +02:00
|
|
|
{ c.emplace_back(IntType(i)); }
|
2022-08-24 14:40:47 +02:00
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::string name() const
|
2022-08-24 14:40:47 +02:00
|
|
|
{ return "emplace_back"; }
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-06 12:46:25 +02:00
|
|
|
template <class IntType>
|
2026-06-23 10:43:34 +02:00
|
|
|
struct insert_near_end_rpt
|
2020-08-10 00:16:58 +02:00
|
|
|
{
|
2026-06-23 10:43:34 +02:00
|
|
|
explicit insert_near_end_rpt(std::size_t n)
|
2026-06-23 00:39:59 +02:00
|
|
|
: range_(bench_range_size(n))
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
std::size_t capacity_multiplier() const
|
|
|
|
|
{ return range_; }
|
2020-08-10 00:16:58 +02:00
|
|
|
|
|
|
|
|
template<class C>
|
2026-02-25 23:13:00 +01:00
|
|
|
BOOST_CONTAINER_FORCEINLINE void operator()(C &c, int i)
|
2026-06-23 00:39:59 +02:00
|
|
|
{
|
|
|
|
|
c.insert(c.size() >= 4*range_
|
|
|
|
|
? c.end() - static_cast<typename C::difference_type>(2*range_)
|
|
|
|
|
: c.end(),
|
|
|
|
|
range_, IntType(i));
|
|
|
|
|
}
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::string name() const
|
|
|
|
|
{ return "insert_near_end_rpt(" + bench_range_label() + ")"; }
|
2026-06-23 00:39:59 +02:00
|
|
|
|
|
|
|
|
std::size_t range_;
|
2020-08-10 00:16:58 +02:00
|
|
|
};
|
|
|
|
|
|
2025-09-06 12:46:25 +02:00
|
|
|
template <class IntType>
|
2020-08-10 00:16:58 +02:00
|
|
|
struct insert_near_end_range
|
|
|
|
|
{
|
2026-06-23 00:39:59 +02:00
|
|
|
explicit insert_near_end_range(std::size_t n)
|
|
|
|
|
: range_(bench_range_size(n)), a_(range_, IntType(0))
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
std::size_t capacity_multiplier() const
|
|
|
|
|
{ return range_; }
|
2020-08-10 00:16:58 +02:00
|
|
|
|
|
|
|
|
template<class C>
|
2026-02-25 23:13:00 +01:00
|
|
|
BOOST_CONTAINER_FORCEINLINE void operator()(C &c, int)
|
2020-08-10 00:16:58 +02:00
|
|
|
{
|
2026-06-23 00:39:59 +02:00
|
|
|
c.insert(c.size() >= 4*range_
|
|
|
|
|
? c.end() - static_cast<typename C::difference_type>(2*range_)
|
|
|
|
|
: c.end(),
|
|
|
|
|
&a_[0], &a_[0]+range_);
|
2020-08-10 00:16:58 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::string name() const
|
2026-06-23 00:39:59 +02:00
|
|
|
{ return "insert_near_end_range(" + bench_range_label() + ")"; }
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
std::size_t range_;
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::vector<IntType> a_;
|
2020-08-10 00:16:58 +02:00
|
|
|
};
|
|
|
|
|
|
2025-09-06 12:46:25 +02:00
|
|
|
template <class IntType>
|
2020-08-10 00:16:58 +02:00
|
|
|
struct insert_near_end
|
|
|
|
|
{
|
2026-06-23 00:39:59 +02:00
|
|
|
explicit insert_near_end(std::size_t) {}
|
|
|
|
|
|
|
|
|
|
std::size_t capacity_multiplier() const
|
2020-08-10 00:16:58 +02:00
|
|
|
{ return 1; }
|
|
|
|
|
|
|
|
|
|
template<class C>
|
2026-02-25 23:13:00 +01:00
|
|
|
BOOST_CONTAINER_FORCEINLINE void operator()(C &c, int i)
|
2020-08-10 00:16:58 +02:00
|
|
|
{
|
|
|
|
|
typedef typename C::iterator it_t;
|
|
|
|
|
it_t it (c.end());
|
2026-02-25 23:13:00 +01:00
|
|
|
it -= static_cast<typename C::difference_type>(c.size() >= 4)*2;
|
2025-09-06 12:46:25 +02:00
|
|
|
c.insert(it, IntType(i));
|
2020-08-10 00:16:58 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::string name() const
|
2020-08-10 00:16:58 +02:00
|
|
|
{ return "insert_near_end"; }
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-06 12:46:25 +02:00
|
|
|
template <class IntType>
|
2022-08-24 14:40:47 +02:00
|
|
|
struct emplace_near_end
|
|
|
|
|
{
|
2026-06-23 00:39:59 +02:00
|
|
|
explicit emplace_near_end(std::size_t) {}
|
|
|
|
|
|
|
|
|
|
std::size_t capacity_multiplier() const
|
|
|
|
|
{ return 1; }
|
2022-08-24 14:40:47 +02:00
|
|
|
|
|
|
|
|
template<class C>
|
2026-02-25 23:13:00 +01:00
|
|
|
BOOST_CONTAINER_FORCEINLINE void operator()(C& c, int i)
|
2022-08-24 14:40:47 +02:00
|
|
|
{
|
|
|
|
|
typedef typename C::iterator it_t;
|
|
|
|
|
it_t it(c.end());
|
2026-02-25 23:13:00 +01:00
|
|
|
it -= static_cast<typename C::difference_type>(c.size() >= 4) * 2;
|
2025-09-20 10:48:50 +02:00
|
|
|
c.emplace(it, IntType(i));
|
2022-08-24 14:40:47 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::string name() const
|
2026-06-23 00:39:59 +02:00
|
|
|
{ return "emplace_near_end"; }
|
2022-08-24 14:40:47 +02:00
|
|
|
};
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Auto-scaling measurement with DSE barriers.
|
|
|
|
|
//
|
|
|
|
|
// A "measured run" builds one container of num_elements via repeated operations.
|
|
|
|
|
// Construction, the optional reserve and the destruction are excluded from the
|
|
|
|
|
// timing using the pause/resume mechanism (the same approach as
|
|
|
|
|
// bench_node_cont.hpp): the measured wall-clock is total - excluded.
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
namespace bench_vector_detail {
|
|
|
|
|
|
|
|
|
|
typedef boost::move_detail::nanosecond_type nsec_t;
|
|
|
|
|
|
|
|
|
|
//measure_start is advanced forward by resume_timing() so that
|
|
|
|
|
//(now - measure_start) yields measured (non-paused) time.
|
|
|
|
|
static nsec_t measure_start = 0;
|
|
|
|
|
static nsec_t measure_pause = 0;
|
|
|
|
|
|
|
|
|
|
BOOST_CONTAINER_FORCEINLINE void pause_timing()
|
|
|
|
|
{ measure_pause = boost::move_detail::nsec_clock(); }
|
|
|
|
|
|
|
|
|
|
BOOST_CONTAINER_FORCEINLINE void resume_timing()
|
|
|
|
|
{ measure_start += boost::move_detail::nsec_clock() - measure_pause; }
|
|
|
|
|
|
|
|
|
|
template<typename F>
|
|
|
|
|
BOOST_NOINLINE double measure(F f, std::size_t num_trials, nsec_t min_time_per_trial)
|
2020-08-10 00:16:58 +02:00
|
|
|
{
|
2026-06-23 00:39:59 +02:00
|
|
|
if(!num_trials) num_trials = 1;
|
2020-08-10 11:19:01 +02:00
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::vector<double> trials(num_trials);
|
2026-06-23 00:39:59 +02:00
|
|
|
for(std::size_t i = 0; i < num_trials; ++i) {
|
|
|
|
|
std::size_t runs = 0;
|
|
|
|
|
nsec_t t1;
|
|
|
|
|
nsec_t t2;
|
2020-08-10 11:19:01 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
measure_start = t1 = boost::move_detail::nsec_clock();
|
|
|
|
|
do {
|
|
|
|
|
clobber();
|
|
|
|
|
unsigned res = f();
|
|
|
|
|
escape(&res);
|
|
|
|
|
t2 = boost::move_detail::nsec_clock();
|
|
|
|
|
++runs;
|
|
|
|
|
} while((t2 - t1) < min_time_per_trial);
|
|
|
|
|
trials[i] = double(t2 - measure_start) / 1.0e9 / double(runs);
|
2020-08-10 00:16:58 +02:00
|
|
|
}
|
2026-06-23 00:39:59 +02:00
|
|
|
std::sort(trials.begin(), trials.end());
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
const std::size_t ts = trials.size();
|
2026-06-23 10:43:34 +02:00
|
|
|
const std::size_t ts_discard = ts / 3; //drop the slowest
|
2026-06-23 00:39:59 +02:00
|
|
|
double sum = 0.0;
|
|
|
|
|
for(std::size_t i = ts_discard; i < ts; ++i) sum += trials[i];
|
|
|
|
|
return sum / double(ts - ts_discard);
|
2020-08-10 00:16:58 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
//Builds one Container of n elements with Operation, timing only the inserts.
|
|
|
|
|
//The Operation (which may own a runtime range buffer) and the reserve are set
|
|
|
|
|
//up in the paused region so only the insertions are measured.
|
|
|
|
|
template<class Container, class Operation>
|
|
|
|
|
unsigned build_once(std::size_t n, bool prereserve)
|
2020-08-10 00:16:58 +02:00
|
|
|
{
|
2026-06-23 00:39:59 +02:00
|
|
|
typedef capacity_wrapper<Container> cpw_t;
|
|
|
|
|
unsigned res = 0;
|
|
|
|
|
{
|
|
|
|
|
Container c;
|
|
|
|
|
pause_timing(); //exclude ctor + reserve + op setup
|
|
|
|
|
Operation op(n);
|
|
|
|
|
const std::size_t mult = op.capacity_multiplier();
|
|
|
|
|
const std::size_t count = mult ? n / mult : 0u;
|
|
|
|
|
if(prereserve) cpw_t::set_reserve(c, n);
|
|
|
|
|
resume_timing();
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
int i = 0;
|
|
|
|
|
for(std::size_t e = 0; e < count; ++e)
|
|
|
|
|
op(c, static_cast<int>(i++));
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
res = static_cast<unsigned>(c.size());
|
|
|
|
|
pause_timing(); //exclude destruction
|
|
|
|
|
} //~Container()/~Operation() (paused)
|
|
|
|
|
resume_timing();
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2025-09-06 12:46:25 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
} //namespace bench_vector_detail
|
2025-09-06 12:46:25 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Friendly type names for the report header.
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
template<class T> inline const char* bench_type_name() { return typeid(T).name(); }
|
|
|
|
|
template<> inline const char* bench_type_name<int>() { return "int"; }
|
|
|
|
|
template<> inline const char* bench_type_name<unsigned>() { return "unsigned"; }
|
|
|
|
|
template<> inline const char* bench_type_name<long>() { return "long"; }
|
|
|
|
|
template<> inline const char* bench_type_name<float>() { return "float"; }
|
|
|
|
|
template<> inline const char* bench_type_name<double>() { return "double"; }
|
|
|
|
|
#ifdef BOOST_HAS_LONG_LONG
|
|
|
|
|
template<> inline const char* bench_type_name< ::boost::long_long_type>() { return "long long"; }
|
2025-09-06 12:46:25 +02:00
|
|
|
#endif
|
|
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Report: collects per (operation,size) seconds for every container column and
|
|
|
|
|
// prints a compact ratio table (each column divided by the first/baseline).
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2026-06-23 10:43:34 +02:00
|
|
|
inline bc::string bench_fmt2(double v)
|
2026-06-23 00:39:59 +02:00
|
|
|
{
|
|
|
|
|
std::ostringstream o;
|
|
|
|
|
o << std::fixed << std::setprecision(2) << v;
|
2026-06-23 10:43:34 +02:00
|
|
|
return bc::string(o.str().c_str());
|
2026-06-23 00:39:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class report
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
struct row
|
|
|
|
|
{
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::string op;
|
|
|
|
|
std::size_t size_exp;
|
|
|
|
|
std::size_t n_eff;
|
|
|
|
|
bc::vector<double> sec; //one per column; sec[0] is the baseline
|
2026-06-23 00:39:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
report(const char* elem_name, bool prereserve)
|
|
|
|
|
: elem_name_(elem_name), prereserve_(prereserve)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
bool has_columns() const { return !cols_.empty(); }
|
|
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
void set_columns(const bc::vector<bc::string>& names) { cols_ = names; }
|
2026-06-23 00:39:59 +02:00
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
void add_row(const bc::string& op, std::size_t size_exp,
|
|
|
|
|
std::size_t n_eff, const bc::vector<double>& sec)
|
2026-06-23 00:39:59 +02:00
|
|
|
{
|
|
|
|
|
row r;
|
|
|
|
|
r.op = op;
|
|
|
|
|
r.size_exp = size_exp;
|
|
|
|
|
r.n_eff = n_eff;
|
|
|
|
|
r.sec = sec;
|
|
|
|
|
rows_.push_back(r);
|
2022-08-24 14:40:47 +02:00
|
|
|
}
|
2026-06-23 00:39:59 +02:00
|
|
|
|
|
|
|
|
void print() const
|
|
|
|
|
{
|
|
|
|
|
const int op_w = 30, size_w = 7, col_w = 14;
|
2026-06-23 10:43:34 +02:00
|
|
|
//The baseline column (index 0) is always 1.0, so it is not printed.
|
|
|
|
|
const int printed_cols = cols_.empty() ? 0 : static_cast<int>(cols_.size()) - 1;
|
|
|
|
|
const int line_w = op_w + size_w + col_w * printed_cols;
|
2026-06-23 00:39:59 +02:00
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
std::cout << "\n" << bc::string(41, '=') << "\n"
|
2026-06-23 00:39:59 +02:00
|
|
|
<< "element=" << elem_name_
|
|
|
|
|
<< " prereserve=" << (prereserve_ ? "1" : "0") << "\n";
|
|
|
|
|
if(!cols_.empty())
|
|
|
|
|
std::cout << "ratio vs '" << cols_[0] << "' (denominator), lower is faster\n";
|
2026-06-23 10:43:34 +02:00
|
|
|
std::cout << bc::string(41, '=') << "\n";
|
2026-06-23 00:39:59 +02:00
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
//Header: operation, size and one column per container (baseline omitted).
|
2026-06-23 00:39:59 +02:00
|
|
|
std::cout << std::left << std::setw(op_w) << "operation"
|
|
|
|
|
<< std::right << std::setw(size_w) << "size";
|
2026-06-23 10:43:34 +02:00
|
|
|
for(std::size_t c = 1; c < cols_.size(); ++c)
|
2026-06-23 00:39:59 +02:00
|
|
|
std::cout << std::setw(col_w) << cols_[c];
|
|
|
|
|
std::cout << "\n";
|
|
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
//Data rows, grouped per operation. After each operation's size sweep a
|
|
|
|
|
//separator and a "geomeans" line (per-column geomean across that
|
|
|
|
|
//operation's sizes) are printed, followed by a blank separating line.
|
|
|
|
|
std::size_t i = 0;
|
|
|
|
|
while(i < rows_.size()) {
|
|
|
|
|
std::size_t j = i;
|
|
|
|
|
while(j < rows_.size() && rows_[j].op == rows_[i].op) ++j;
|
|
|
|
|
|
|
|
|
|
for(std::size_t k = i; k < j; ++k) {
|
|
|
|
|
const row& r = rows_[k];
|
|
|
|
|
std::ostringstream se;
|
|
|
|
|
se << "1.E" << r.size_exp;
|
|
|
|
|
std::cout << std::left << std::setw(op_w) << r.op
|
|
|
|
|
<< std::right << std::setw(size_w) << se.str();
|
|
|
|
|
const double base = r.sec.empty() ? 0.0 : r.sec[0];
|
|
|
|
|
for(std::size_t c = 1; c < r.sec.size(); ++c) {
|
|
|
|
|
const double ratio = base > 0.0 ? r.sec[c] / base : 0.0;
|
|
|
|
|
std::cout << std::setw(col_w) << bench_fmt2(ratio);
|
|
|
|
|
}
|
|
|
|
|
std::cout << "\n";
|
2026-06-23 00:39:59 +02:00
|
|
|
}
|
2026-06-23 10:43:34 +02:00
|
|
|
|
|
|
|
|
std::cout << bc::string(static_cast<bc::string::size_type>(line_w), '-') << "\n";
|
|
|
|
|
std::cout << std::left << std::setw(op_w) << "geomeans"
|
|
|
|
|
<< std::right << std::setw(size_w) << "";
|
|
|
|
|
for(std::size_t c = 1; c < cols_.size(); ++c)
|
|
|
|
|
std::cout << std::setw(col_w) << bench_fmt2(column_geomean_range(c, i, j));
|
|
|
|
|
std::cout << "\n\n";
|
|
|
|
|
|
|
|
|
|
i = j;
|
2026-06-23 00:39:59 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
//Overall footer: per-column geomean across every operation/size, then the
|
|
|
|
|
//general geomean over every ratio cell of the table on its own line.
|
|
|
|
|
std::cout << bc::string(static_cast<bc::string::size_type>(line_w), '-') << "\n";
|
|
|
|
|
std::cout << std::left << std::setw(op_w) << "geomean (all)"
|
2026-06-23 00:39:59 +02:00
|
|
|
<< std::right << std::setw(size_w) << "";
|
2026-06-23 10:43:34 +02:00
|
|
|
for(std::size_t c = 1; c < cols_.size(); ++c)
|
2026-06-23 00:39:59 +02:00
|
|
|
std::cout << std::setw(col_w) << bench_fmt2(column_geomean(c));
|
|
|
|
|
std::cout << "\n";
|
|
|
|
|
std::cout << std::left << std::setw(op_w) << "general geomean"
|
|
|
|
|
<< std::right << bench_fmt2(general_geomean()) << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2026-06-23 10:43:34 +02:00
|
|
|
//Geomean of one container column's ratios over the row range [begin, end).
|
|
|
|
|
double column_geomean_range(std::size_t c, std::size_t begin, std::size_t end) const
|
2026-06-23 00:39:59 +02:00
|
|
|
{
|
|
|
|
|
double log_sum = 0.0;
|
|
|
|
|
std::size_t count = 0;
|
2026-06-23 10:43:34 +02:00
|
|
|
for(std::size_t i = begin; i < end; ++i) {
|
2026-06-23 00:39:59 +02:00
|
|
|
const row& r = rows_[i];
|
|
|
|
|
if(c < r.sec.size() && !r.sec.empty() && r.sec[0] > 0.0 && r.sec[c] > 0.0) {
|
|
|
|
|
log_sum += std::log(r.sec[c] / r.sec[0]);
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count ? std::exp(log_sum / double(count)) : 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
//Geomean of one container column's ratios across all rows (vertical).
|
|
|
|
|
double column_geomean(std::size_t c) const
|
|
|
|
|
{ return column_geomean_range(c, 0, rows_.size()); }
|
|
|
|
|
|
|
|
|
|
//Geomean over every ratio cell of the table (all rows, all non-baseline
|
|
|
|
|
//columns; the baseline column is excluded since it is always 1.0).
|
2026-06-23 00:39:59 +02:00
|
|
|
double general_geomean() const
|
|
|
|
|
{
|
|
|
|
|
double log_sum = 0.0;
|
|
|
|
|
std::size_t count = 0;
|
|
|
|
|
for(std::size_t i = 0; i < rows_.size(); ++i) {
|
|
|
|
|
const row& r = rows_[i];
|
|
|
|
|
const double base = r.sec.empty() ? 0.0 : r.sec[0];
|
|
|
|
|
if(base > 0.0) {
|
2026-06-23 10:43:34 +02:00
|
|
|
for(std::size_t c = 1; c < r.sec.size(); ++c) {
|
2026-06-23 00:39:59 +02:00
|
|
|
if(r.sec[c] > 0.0) { log_sum += std::log(r.sec[c] / base); ++count; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count ? std::exp(log_sum / double(count)) : 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::string elem_name_;
|
|
|
|
|
bool prereserve_;
|
|
|
|
|
bc::vector<bc::string> cols_;
|
|
|
|
|
bc::vector<row> rows_;
|
2026-06-23 00:39:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// runner: the customization point's argument. A runner registers each container
|
|
|
|
|
// with add<Container>(name); the FIRST one registered is the baseline. add()
|
|
|
|
|
// measures the container across the whole size sweep; flush() (called by the
|
|
|
|
|
// harness) appends the rows to the shared report.
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
inline std::size_t bench_num_sizes()
|
|
|
|
|
{ return bench_vector_defaults::max_size_exp - bench_vector_defaults::min_size_exp + 1u; }
|
|
|
|
|
|
|
|
|
|
template<class IntType, class Operation>
|
|
|
|
|
class runner
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
runner(report& rep, bool prereserve)
|
|
|
|
|
: rep_(rep), prereserve_(prereserve), sec_by_size_(bench_num_sizes())
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
template<class Container>
|
|
|
|
|
void add(const char* name)
|
|
|
|
|
{
|
|
|
|
|
using namespace bench_vector_detail;
|
|
|
|
|
names_.push_back(name);
|
|
|
|
|
for(std::size_t si = 0; si < bench_num_sizes(); ++si) {
|
|
|
|
|
const std::size_t exp = bench_vector_defaults::min_size_exp + si;
|
|
|
|
|
const std::size_t n = bench_pow10(exp);
|
|
|
|
|
const double sec = measure(
|
|
|
|
|
container_build<Container>(n, prereserve_),
|
|
|
|
|
bench_vector_defaults::num_trials,
|
|
|
|
|
bench_vector_defaults::min_time_per_trial);
|
|
|
|
|
sec_by_size_[si].push_back(sec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void flush()
|
|
|
|
|
{
|
|
|
|
|
if(!rep_.has_columns())
|
|
|
|
|
rep_.set_columns(names_);
|
|
|
|
|
for(std::size_t si = 0; si < bench_num_sizes(); ++si) {
|
|
|
|
|
const std::size_t exp = bench_vector_defaults::min_size_exp + si;
|
|
|
|
|
const std::size_t n = bench_pow10(exp);
|
|
|
|
|
Operation op(n);
|
|
|
|
|
const std::size_t mult = op.capacity_multiplier();
|
|
|
|
|
const std::size_t n_eff = mult ? (n / mult) * mult : 0u;
|
|
|
|
|
rep_.add_row(op.name(), exp, n_eff, sec_by_size_[si]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
//Callable adapter so measure() (which expects f()) can build a Container.
|
|
|
|
|
template<class Container>
|
|
|
|
|
struct container_build
|
|
|
|
|
{
|
|
|
|
|
std::size_t n;
|
|
|
|
|
bool prereserve;
|
|
|
|
|
container_build(std::size_t n_, bool pr) : n(n_), prereserve(pr) {}
|
|
|
|
|
unsigned operator()() const
|
|
|
|
|
{ return bench_vector_detail::build_once<Container, Operation>(n, prereserve); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
report& rep_;
|
|
|
|
|
bool prereserve_;
|
2026-06-23 10:43:34 +02:00
|
|
|
bc::vector<bc::string> names_;
|
|
|
|
|
bc::vector<bc::vector<double> > sec_by_size_; //[size_index][column]
|
2026-06-23 00:39:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Customization point implemented by every runner: register (with add<>()) each
|
|
|
|
|
//container it wants to compare. The first one registered is the baseline.
|
|
|
|
|
template<class IntType, class Operation>
|
|
|
|
|
void run_containers(runner<IntType, Operation>& r);
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Drivers.
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
template<class IntType, class Operation>
|
|
|
|
|
void add_operation(report& rep, bool prereserve)
|
|
|
|
|
{
|
|
|
|
|
runner<IntType, Operation> r(rep, prereserve);
|
|
|
|
|
run_containers<IntType, Operation>(r);
|
|
|
|
|
r.flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class IntType>
|
|
|
|
|
void test_vectors_pass(bool prereserve)
|
|
|
|
|
{
|
|
|
|
|
report rep(bench_type_name<IntType>(), prereserve);
|
|
|
|
|
|
|
|
|
|
//end
|
|
|
|
|
add_operation<IntType, push_back<IntType> >(rep, prereserve);
|
|
|
|
|
#if BOOST_CXX_VERSION >= 201103L
|
|
|
|
|
add_operation<IntType, emplace_back<IntType> >(rep, prereserve);
|
|
|
|
|
#endif
|
|
|
|
|
add_operation<IntType, insert_end_range<IntType> >(rep, prereserve);
|
|
|
|
|
add_operation<IntType, insert_end_repeated<IntType> >(rep, prereserve);
|
|
|
|
|
|
|
|
|
|
//near end
|
|
|
|
|
add_operation<IntType, insert_near_end<IntType> >(rep, prereserve);
|
|
|
|
|
#if BOOST_CXX_VERSION >= 201103L
|
|
|
|
|
add_operation<IntType, emplace_near_end<IntType> >(rep, prereserve);
|
|
|
|
|
#endif
|
|
|
|
|
add_operation<IntType, insert_near_end_range<IntType> >(rep, prereserve);
|
2026-06-23 10:43:34 +02:00
|
|
|
add_operation<IntType, insert_near_end_rpt<IntType> >(rep, prereserve);
|
2026-06-23 00:39:59 +02:00
|
|
|
|
|
|
|
|
rep.print();
|
2020-08-10 00:16:58 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-06 12:46:25 +02:00
|
|
|
template<class IntType>
|
|
|
|
|
void test_vectors()
|
2020-08-10 00:16:58 +02:00
|
|
|
{
|
2026-06-23 00:39:59 +02:00
|
|
|
std::cout << "Benchmark config: sizes 1.E" << bench_vector_defaults::min_size_exp
|
|
|
|
|
<< " .. 1.E" << bench_vector_defaults::max_size_exp
|
|
|
|
|
<< ", trials " << bench_vector_defaults::num_trials
|
|
|
|
|
<< ", min " << (bench_vector_defaults::min_time_per_trial / 1000000)
|
|
|
|
|
<< " ms/trial\n";
|
2020-08-10 00:16:58 +02:00
|
|
|
|
2026-06-23 00:39:59 +02:00
|
|
|
if(bench_vector_defaults::run_noreserve)
|
|
|
|
|
test_vectors_pass<IntType>(false);
|
|
|
|
|
if(bench_vector_defaults::run_prereserve)
|
|
|
|
|
test_vectors_pass<IntType>(true);
|
2025-09-06 12:46:25 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-21 21:07:55 +02:00
|
|
|
#endif //BOOST_CONTAINER_BENCH_VECTOR_COMMON_HPP
|