1 // Boost.Geometry Index
2 // Additional tests
3 
4 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
5 
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 #include <iostream>
11 
12 #include <boost/geometry.hpp>
13 #include <boost/geometry/index/rtree.hpp>
14 
15 #include <boost/chrono.hpp>
16 #include <boost/foreach.hpp>
17 #include <boost/random.hpp>
18 #include <set>
19 
main()20 int main()
21 {
22     namespace bg = boost::geometry;
23     namespace bgi = bg::index;
24     typedef boost::chrono::thread_clock clock_t;
25     typedef boost::chrono::duration<float> dur_t;
26 
27     size_t stored_count = 100000;
28 
29     std::vector< std::pair<float, float> > coords;
30 
31     //randomize values
32     {
33         boost::mt19937 rng;
34         //rng.seed(static_cast<unsigned int>(std::time(0)));
35         float max_val = static_cast<float>(stored_count / 10);
36         boost::uniform_real<float> range(-max_val, max_val);
37         boost::variate_generator<boost::mt19937&, boost::uniform_real<float> > rnd(rng, range);
38 
39         coords.reserve(stored_count);
40 
41         std::cout << "randomizing data\n";
42         for ( size_t i = 0 ; i < stored_count ; ++i )
43         {
44             coords.push_back(std::make_pair(rnd(), rnd()));
45         }
46         std::cout << "randomized\n";
47     }
48 
49     typedef bg::model::point<float, 2, bg::cs::cartesian> P;
50     typedef bgi::rtree<P, bgi::dynamic_linear > RTL;
51     typedef bgi::rtree<P, bgi::dynamic_quadratic > RTQ;
52     typedef bgi::rtree<P, bgi::dynamic_rstar > RTR;
53 
54     for ( size_t m = 4 ; m < 33 ; m += 2 )
55     {
56         size_t mm = ::ceil(m / 3.0f);
57 
58         RTL rtl(bgi::dynamic_linear(m, mm));
59         RTQ rtq(bgi::dynamic_quadratic(m, mm));
60         RTR rtr(bgi::dynamic_rstar(m, mm));
61 
62         std::cout << m << ' ' << mm << ' ';
63 
64         // inserting test
65         {
66             clock_t::time_point start = clock_t::now();
67             for (size_t i = 0 ; i < stored_count ; ++i )
68             {
69                 P p(coords[i].first, coords[i].second);
70                 rtl.insert(p);
71             }
72             dur_t time = clock_t::now() - start;
73             std::cout << time.count() << ' ';
74 
75             start = clock_t::now();
76             for (size_t i = 0 ; i < stored_count ; ++i )
77             {
78                 P p(coords[i].first, coords[i].second);
79                 rtq.insert(p);
80             }
81             time = clock_t::now() - start;
82             std::cout << time.count() << ' ';
83 
84             start = clock_t::now();
85             for (size_t i = 0 ; i < stored_count ; ++i )
86             {
87                 float v = i / 100.0f;
88                 P p(coords[i].first, coords[i].second);
89                 rtr.insert(p);
90             }
91             time = clock_t::now() - start;
92             std::cout << time.count() << ' ';
93         }
94 
95         std::cout << '\n';
96     }
97 
98     return 0;
99 }
100