41 lines
1 KiB
C++
41 lines
1 KiB
C++
|
#include "bench_framework.hpp"
|
||
|
#include <mapnik/quad_tree.hpp>
|
||
|
#include <random>
|
||
|
|
||
|
using quad_tree_type = mapnik::quad_tree<std::size_t>;
|
||
|
|
||
|
class test : public benchmark::test_case
|
||
|
{
|
||
|
public:
|
||
|
test(mapnik::parameters const& params)
|
||
|
: test_case(params) {}
|
||
|
|
||
|
bool validate() const
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool operator()() const
|
||
|
{
|
||
|
std::random_device rd;
|
||
|
std::default_random_engine engine(rd());
|
||
|
std::uniform_int_distribution<int> uniform_dist(0, 2048);
|
||
|
std::size_t count = 0;
|
||
|
quad_tree_type tree(mapnik::box2d<double>(0,0,2048,2048));
|
||
|
for (size_t i = 0; i < iterations_; ++i)
|
||
|
{
|
||
|
int cx = uniform_dist(engine);
|
||
|
int cy = uniform_dist(engine);
|
||
|
int sx = 0.2 * uniform_dist(engine);
|
||
|
int sy = 0.2 * uniform_dist(engine);
|
||
|
mapnik::box2d<double> box(cx - sx,cy - sy, cx + sx, cy + sy);
|
||
|
tree.insert(i, box);
|
||
|
count++;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
BENCHMARK(test,"quad_tree creation")
|