]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/index/example/3d_benchmark.cpp
1 // Boost.Geometry Index
4 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
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)
11 #include <boost/geometry/index/rtree.hpp>
13 #include <boost/chrono.hpp>
14 #include <boost/foreach.hpp>
15 #include <boost/random.hpp>
19 namespace bg
= boost::geometry
;
20 namespace bgi
= bg::index
;
21 typedef boost::chrono::thread_clock
clock_t;
22 typedef boost::chrono::duration
<float> dur_t
;
24 size_t values_count
= 500000;
25 size_t queries_count
= 200000;
27 std::vector
< boost::tuple
<float, float, float> > coords
;
32 //rng.seed(static_cast<unsigned int>(std::time(0)));
33 float max_val
= static_cast<float>(values_count
/ 2);
34 boost::uniform_real
<float> range(-max_val
, max_val
);
35 boost::variate_generator
<boost::mt19937
&, boost::uniform_real
<float> > rnd(rng
, range
);
37 coords
.reserve(values_count
);
39 std::cout
<< "randomizing data\n";
40 for ( size_t i
= 0 ; i
< values_count
; ++i
)
42 coords
.push_back(boost::make_tuple(rnd(), rnd(), rnd()));
44 std::cout
<< "randomized\n";
47 typedef bg::model::point
<float, 3, bg::cs::cartesian
> P
;
48 typedef bg::model::box
<P
> B
;
49 //typedef bgi::rtree<B, bgi::linear<32, 8> > RT;
50 //typedef bgi::rtree<B, bgi::quadratic<32, 8> > RT;
51 typedef bgi::rtree
<B
, bgi::rstar
<8, 3> > RT
;
53 std::cout
<< "sizeof rtree: " << sizeof(RT
) << std::endl
;
61 clock_t::time_point start
= clock_t::now();
62 for (size_t i
= 0 ; i
< values_count
; ++i
)
64 float x
= boost::get
<0>(coords
[i
]);
65 float y
= boost::get
<1>(coords
[i
]);
66 float z
= boost::get
<2>(coords
[i
]);
67 B
b(P(x
- 0.5f
, y
- 0.5f
, z
- 0.5f
), P(x
+ 0.5f
, y
+ 0.5f
, z
+ 0.5f
));
71 dur_t time
= clock_t::now() - start
;
72 std::cout
<< time
<< " - insert " << values_count
<< '\n';
75 std::vector
<B
> result
;
80 clock_t::time_point start
= clock_t::now();
82 for (size_t i
= 0 ; i
< queries_count
; ++i
)
84 float x
= boost::get
<0>(coords
[i
]);
85 float y
= boost::get
<1>(coords
[i
]);
86 float z
= boost::get
<2>(coords
[i
]);
88 t
.query(bgi::intersects(B(P(x
- 10, y
- 10, z
- 10), P(x
+ 10, y
+ 10, z
+ 10))), std::back_inserter(result
));
89 temp
+= result
.size();
91 dur_t time
= clock_t::now() - start
;
92 std::cout
<< time
<< " - query(B) " << queries_count
<< " found " << temp
<< '\n';
96 clock_t::time_point start
= clock_t::now();
98 for (size_t i
= 0 ; i
< queries_count
/ 2 ; ++i
)
100 float x1
= boost::get
<0>(coords
[i
]);
101 float y1
= boost::get
<1>(coords
[i
]);
102 float z1
= boost::get
<2>(coords
[i
]);
103 float x2
= boost::get
<0>(coords
[i
+1]);
104 float y2
= boost::get
<1>(coords
[i
+1]);
105 float z2
= boost::get
<2>(coords
[i
+1]);
106 float x3
= boost::get
<0>(coords
[i
+2]);
107 float y3
= boost::get
<1>(coords
[i
+2]);
108 float z3
= boost::get
<2>(coords
[i
+2]);
111 bgi::intersects(B(P(x1
- 10, y1
- 10, z1
- 10), P(x1
+ 10, y1
+ 10, z1
+ 10)))
113 !bgi::within(B(P(x2
- 10, y2
- 10, z2
- 10), P(x2
+ 10, y2
+ 10, z2
+ 10)))
115 !bgi::overlaps(B(P(x3
- 10, y3
- 10, z3
- 10), P(x3
+ 10, y3
+ 10, z3
+ 10)))
117 std::back_inserter(result
)
119 temp
+= result
.size();
121 dur_t time
= clock_t::now() - start
;
122 std::cout
<< time
<< " - query(i && !w && !o) " << queries_count
<< " found " << temp
<< '\n';
128 clock_t::time_point start
= clock_t::now();
130 for (size_t i
= 0 ; i
< queries_count
/ 10 ; ++i
)
132 float x
= boost::get
<0>(coords
[i
]) - 100;
133 float y
= boost::get
<1>(coords
[i
]) - 100;
134 float z
= boost::get
<2>(coords
[i
]) - 100;
136 temp
+= t
.query(bgi::nearest(P(x
, y
, z
), 5), std::back_inserter(result
));
138 dur_t time
= clock_t::now() - start
;
139 std::cout
<< time
<< " - query(nearest(P, 5)) " << (queries_count
/ 10) << " found " << temp
<< '\n';
143 clock_t::time_point start
= clock_t::now();
144 for (size_t i
= 0 ; i
< values_count
/ 10 ; ++i
)
146 float x
= boost::get
<0>(coords
[i
]);
147 float y
= boost::get
<1>(coords
[i
]);
148 float z
= boost::get
<2>(coords
[i
]);
149 B
b(P(x
- 0.5f
, y
- 0.5f
, z
- 0.5f
), P(x
+ 0.5f
, y
+ 0.5f
, z
+ 0.5f
));
153 dur_t time
= clock_t::now() - start
;
154 std::cout
<< time
<< " - remove " << values_count
/ 10 << '\n';
157 std::cout
<< "------------------------------------------------\n";