1
/*************************************************************************
3
* Copyright (c) 2011-2013 Kohei Yoshida
5
* Permission is hereby granted, free of charge, to any person
6
* obtaining a copy of this software and associated documentation
7
* files (the "Software"), to deal in the Software without
8
* restriction, including without limitation the rights to use,
9
* copy, modify, merge, publish, distribute, sublicense, and/or sell
10
* copies of the Software, and to permit persons to whom the
11
* Software is furnished to do so, subject to the following
14
* The above copyright notice and this permission notice shall be
15
* included in all copies or substantial portions of the Software.
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
* OTHER DEALINGS IN THE SOFTWARE.
26
************************************************************************/
28
#include "test_global.hpp"
30
#include <mdds/multi_type_vector.hpp>
31
#include <mdds/multi_type_vector_trait.hpp>
38
#include <boost/ptr_container/ptr_vector.hpp>
39
#include <boost/noncopyable.hpp>
41
#define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
48
typedef mdds::multi_type_vector<mdds::mtv::element_block_func> mtv_type;
50
void mtv_perf_test_block_position_lookup()
55
// Default insertion which always looks up the right element block
56
// from the position of the first block. As such, as the block size
57
// grows, so does the time it takes to search for the right block.
62
stack_printer __stack_printer__("::mtv_perf_test_block_position_lookup::default insertion");
63
for (size_t i = 0; i < n; ++i)
65
size_t pos1 = i*2, pos2 = i*2 + 1;
72
// As a solution for this, we can use an iterator to specify the start
73
// position, which eliminates the above scalability problem nicely.
76
mtv_type::iterator pos_hint = db.begin();
79
stack_printer __stack_printer__("::mtv_perf_test_block_position_lookup::insertion with position hint");
80
for (size_t i = 0; i < n; ++i)
82
size_t pos1 = i*2, pos2 = i*2 + 1;
83
pos_hint = db.set(pos_hint, pos1, val1);
84
pos_hint = db.set(pos_hint, pos2, val2);
89
void mtv_perf_test_insert_via_position_object()
91
size_t data_size = 80000;
92
mtv_type db(data_size);
94
stack_printer __stack_printer__("::mtv_perf_test_insert_via_position_object initialize mtv.");
95
mtv_type::iterator it = db.begin();
96
for (size_t i = 0, n = db.size() / 2; i < n; ++i)
98
it = db.set(it, i*2, 1.1);
104
stack_printer __stack_printer__("::mtv_perf_test_insert_via_position_object insert with position hint.");
105
mtv_type::iterator it = db2.begin();
106
for (size_t i = 0, n = db2.size(); i < n; ++i)
108
it = db2.set(it, i, string("foo"));
114
stack_printer __stack_printer__("::mtv_perf_test_insert_via_position_object insert via position object.");
115
mtv_type::position_type pos = db2.position(0);
116
for (; pos.first != db2.end(); pos = mtv_type::next_position(pos))
118
size_t log_pos = mtv_type::logical_position(pos);
119
pos.first = db2.set(pos.first, log_pos, string("foo"));
120
pos.second = log_pos - pos.first->position;
127
int main (int argc, char **argv)
129
mtv_perf_test_block_position_lookup();
130
mtv_perf_test_insert_via_position_object();