File: test_quad_tree.cpp

package info (click to toggle)
mapnik 3.0.12%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 17,084 kB
  • ctags: 18,454
  • sloc: cpp: 142,516; python: 1,416; sh: 769; makefile: 170; xml: 140; lisp: 13
file content (54 lines) | stat: -rw-r--r-- 1,580 bytes parent folder | download | duplicates (4)
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
#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);
        quad_tree_type tree(mapnik::box2d<double>(0,0,2048,2048));
        //populate
        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);
        }
        // bounding box query
        std::size_t count=0;
        for (size_t i = 0; i < iterations_; ++i)
        {
            int cx = uniform_dist(engine);
            int cy = uniform_dist(engine);
            int sx = 0.4 * uniform_dist(engine);
            int sy = 0.4 * uniform_dist(engine);
            mapnik::box2d<double> box(cx - sx,cy - sy, cx + sx, cy + sy);
            auto itr = tree.query_in_box(box);
            auto end = tree.query_end();
            for ( ;itr != end; ++itr)
            {
                ++count;
            }
        }
        return true;
    }
};

BENCHMARK(test,"quad_tree creation")