Skip to content

Commit 5be25a6

Browse files
committed
Add new deque implementation.
1 parent 7495c15 commit 5be25a6

File tree

7 files changed

+1054
-4355
lines changed

7 files changed

+1054
-4355
lines changed

bench/bench_vectors.cpp

Lines changed: 82 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <deque>
1313
#include <boost/container/vector.hpp>
1414
#include <boost/container/deque.hpp>
15-
#include "new_deque.hpp"
1615
#include <boost/container/devector.hpp>
1716
#include <boost/container/small_vector.hpp>
1817
#include <boost/container/stable_vector.hpp>
@@ -73,6 +72,66 @@ class MyInt
7372
}
7473
};
7574

75+
class MyFatInt
76+
{
77+
int int0_;
78+
int int1_;
79+
int int2_;
80+
int int3_;
81+
int int4_;
82+
int int5_;
83+
int int6_;
84+
int int7_;
85+
86+
public:
87+
inline explicit MyFatInt(int i = 0)
88+
: int0_(i++)
89+
, int1_(i++)
90+
, int2_(i++)
91+
, int3_(i++)
92+
, int4_(i++)
93+
, int5_(i++)
94+
, int6_(i++)
95+
, int7_(i++)
96+
{}
97+
98+
inline MyFatInt(const MyFatInt &other)
99+
: int0_(other.int0_)
100+
, int1_(other.int1_)
101+
, int2_(other.int2_)
102+
, int3_(other.int3_)
103+
, int4_(other.int4_)
104+
, int5_(other.int5_)
105+
, int6_(other.int6_)
106+
, int7_(other.int7_)
107+
{}
108+
109+
inline MyFatInt & operator=(const MyFatInt &other)
110+
{
111+
int0_ = other.int0_;
112+
int1_ = other.int1_;
113+
int2_ = other.int2_;
114+
int3_ = other.int3_;
115+
int4_ = other.int4_;
116+
int5_ = other.int5_;
117+
int6_ = other.int6_;
118+
int7_ = other.int7_;
119+
return *this;
120+
}
121+
122+
inline ~MyFatInt()
123+
{
124+
int0_ = 0u;
125+
int1_ = 0u;
126+
int2_ = 0u;
127+
int3_ = 0u;
128+
int4_ = 0u;
129+
int5_ = 0u;
130+
int6_ = 0u;
131+
int7_ = 0u;
132+
}
133+
};
134+
76135
template<class C, bool = boost::container::test::
77136
has_member_function_callable_with_capacity<C>::value>
78137
struct capacity_wrapper
@@ -99,7 +158,7 @@ const std::size_t RangeSize = 8;
99158
template <class IntType>
100159
struct insert_end_range
101160
{
102-
inline std::size_t capacity_multiplier() const
161+
static inline std::size_t capacity_multiplier()
103162
{ return RangeSize; }
104163

105164
template<class C>
@@ -115,7 +174,7 @@ struct insert_end_range
115174
template <class IntType>
116175
struct insert_end_repeated
117176
{
118-
inline std::size_t capacity_multiplier() const
177+
static inline std::size_t capacity_multiplier()
119178
{ return RangeSize; }
120179

121180
template<class C>
@@ -131,7 +190,7 @@ struct insert_end_repeated
131190
template <class IntType>
132191
struct push_back
133192
{
134-
inline std::size_t capacity_multiplier() const
193+
static inline std::size_t capacity_multiplier()
135194
{ return 1; }
136195

137196
template<class C>
@@ -145,12 +204,12 @@ struct push_back
145204
template <class IntType>
146205
struct emplace_back
147206
{
148-
inline std::size_t capacity_multiplier() const
207+
static inline std::size_t capacity_multiplier()
149208
{ return 1; }
150209

151210
template<class C>
152211
inline void operator()(C &c, int i)
153-
{ c.emplace_back(i); }
212+
{ c.emplace_back(IntType(i)); }
154213

155214
inline const char *name() const
156215
{ return "emplace_back"; }
@@ -159,7 +218,7 @@ struct emplace_back
159218
template <class IntType>
160219
struct insert_near_end_repeated
161220
{
162-
inline std::size_t capacity_multiplier() const
221+
static inline std::size_t capacity_multiplier()
163222
{ return RangeSize; }
164223

165224
template<class C>
@@ -173,7 +232,7 @@ struct insert_near_end_repeated
173232
template <class IntType>
174233
struct insert_near_end_range
175234
{
176-
inline std::size_t capacity_multiplier() const
235+
static inline std::size_t capacity_multiplier()
177236
{ return RangeSize; }
178237

179238
template<class C>
@@ -191,7 +250,7 @@ struct insert_near_end_range
191250
template <class IntType>
192251
struct insert_near_end
193252
{
194-
inline std::size_t capacity_multiplier() const
253+
static inline std::size_t capacity_multiplier()
195254
{ return 1; }
196255

197256
template<class C>
@@ -210,7 +269,7 @@ struct insert_near_end
210269
template <class IntType>
211270
struct emplace_near_end
212271
{
213-
inline std::size_t capacity_multiplier() const
272+
static inline std::size_t capacity_multiplier()
214273
{
215274
return 1;
216275
}
@@ -221,7 +280,7 @@ struct emplace_near_end
221280
typedef typename C::iterator it_t;
222281
it_t it(c.end());
223282
it -= static_cast<typename C::difference_type>(c.size() >= 2) * 2;
224-
c.emplace(it, i);
283+
c.emplace(it, IntType(i));
225284
}
226285

227286
inline const char* name() const
@@ -246,10 +305,9 @@ void vector_test_template(std::size_t num_iterations, std::size_t num_elements,
246305

247306
const std::size_t max = num_elements/multiplier;
248307
for(std::size_t r = 0; r != num_iterations; ++r){
249-
250308
//Unroll the loop to avoid noise from loop code
251309
int i = 0;
252-
if (r > 0) //Exclude first iteration to avoid noise
310+
if (r > num_iterations/10) //Exclude first iterations to avoid noise
253311
timer.resume();
254312
for(std::size_t e = 0; e < max/16; ++e){
255313
op(c, static_cast<int>(i++));
@@ -270,7 +328,7 @@ void vector_test_template(std::size_t num_iterations, std::size_t num_elements,
270328
op(c, static_cast<int>(i++));
271329
}
272330

273-
if (r > 0)
331+
if (r > num_iterations/10)
274332
timer.stop();
275333
c.clear();
276334
}
@@ -303,11 +361,11 @@ void test_vectors_impl()
303361
std::size_t numele [] = { 100000 };
304362
#elif defined SIMPLE_IT
305363
#ifdef NDEBUG
306-
std::size_t numit [] = { 50 };
364+
std::size_t numit [] = { 150 };
307365
#else
308366
std::size_t numit [] = { 10 };
309367
#endif
310-
std::size_t numele [] = { 100000 };
368+
std::size_t numele [] = { 500000 };
311369
#else
312370
#ifdef NDEBUG
313371
unsigned int numit [] = { 1000, 10000, 100000, 1000000 };
@@ -335,8 +393,6 @@ void test_vectors_impl()
335393
#define P_END 1
336394
#endif
337395

338-
typedef bc::vector_options< bc::growth_factor<bc::growth_factor_100> >::type growth_100_option_t;
339-
340396
for (unsigned p = P_INIT; p != P_END; ++p) {
341397
std::cout << "---------------------------------\n";
342398
std::cout << "IntType:" << typeid(IntType).name() << " op:" << Operation().name() << ", prereserve: " << (p ? "1" : "0") << "\n";
@@ -345,14 +401,12 @@ void test_vectors_impl()
345401
const std::size_t it_count = sizeof(numele)/sizeof(numele[0]);
346402
for(unsigned int i = 0; i < it_count; ++i){
347403
std::cout << "\n" << " ---- numit[i]: " << numit[i] << " numele[i] : " << numele[i] << " ---- \n";
348-
vector_test_template< std::vector<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i], "std::vector ", bp);
349-
vector_test_template< bc::vector<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i] , "vector ", bp);
350-
vector_test_template< bc::vector<IntType, std::allocator<IntType>, growth_100_option_t >, Operation >(numit[i], numele[i], "vector(2x) ", bp);
351-
vector_test_template< bc::small_vector<IntType, 0, std::allocator<IntType> >, Operation >(numit[i], numele[i], "small_vector ", bp);
352-
vector_test_template< bc::devector<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i], "devector ", bp);
353-
vector_test_template< std::deque<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i], "std::deque ", bp);
354-
vector_test_template< bc::deque<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i], "deque ", bp);
355-
vector_test_template< bc::new_deque<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i], "new_deque ", bp);
404+
vector_test_template< std::vector<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i], "std::vector ", bp);
405+
vector_test_template< bc::vector<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i] , "vector ", bp);
406+
vector_test_template< bc::small_vector<IntType, 0, std::allocator<IntType> >, Operation >(numit[i], numele[i], "small_vector ", bp);
407+
vector_test_template< bc::devector<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i], "devector ", bp);
408+
vector_test_template< std::deque<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i], "std::deque ", bp);
409+
vector_test_template< bc::deque<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i], "deque ", bp);
356410
}
357411
std::cout << "---------------------------------\n---------------------------------\n";
358412
}
@@ -381,8 +435,9 @@ void test_vectors()
381435

382436
int main()
383437
{
384-
//test_vectors<MyInt>();
385438
test_vectors<int>();
439+
test_vectors<MyInt>();
440+
test_vectors<MyFatInt>();
386441

387442
return 0;
388443
}

0 commit comments

Comments
 (0)