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