1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// Boost.Geometry Index
// Compare performance with std::set using 1-dimensional object
// (i.e. angle, or number line coordiante)
// Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <boost/chrono.hpp>
#include <boost/foreach.hpp>
#include <boost/random.hpp>
#include <set>
int main()
{
namespace bg = boost::geometry;
namespace bgi = bg::index;
typedef boost::chrono::thread_clock clock_t;
typedef boost::chrono::duration<float> dur_t;
size_t values_count = 1001;
size_t count_start = 10;
size_t count_stop = 1000;
size_t count_step = 10;
size_t insrem_count = 3000000;
typedef bg::model::point<float, 1, bg::cs::cartesian> P;
//typedef bgi::rtree<P, bgi::linear<8, 3> > RT;
typedef bgi::rtree<P, bgi::quadratic<8, 3> > RT;
//typedef bgi::rtree<P, bgi::rstar<8, 3> > RT;
RT t;
std::set<float> s;
size_t val_i = 0;
for ( size_t curr_count = count_start ; curr_count < count_stop ; curr_count += count_step )
{
// inserting test
{
for (; val_i < curr_count ; ++val_i )
{
float v = val_i / 100.0f;
P p(v);
t.insert(p);
s.insert(v);
}
float v = (val_i+1) / 100.0f;
P test_p(v);
std::cout << t.size() << ' ';
clock_t::time_point start = clock_t::now();
for (size_t i = 0 ; i < insrem_count ; ++i )
{
t.insert(test_p);
t.remove(test_p);
}
dur_t time = clock_t::now() - start;
std::cout << time.count() << ' ';
start = clock_t::now();
for (size_t i = 0 ; i < insrem_count ; ++i )
{
s.insert(v);
s.erase(v);
}
time = clock_t::now() - start;
std::cout << time.count() << ' ';
}
std::cout << '\n';
}
return 0;
}
|