File: UnaryUnionSegmentsPerfTest.cpp

package info (click to toggle)
geos 3.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,212 kB
  • sloc: cpp: 199,103; xml: 56,065; ansic: 6,162; sh: 287; makefile: 26
file content (71 lines) | stat: -rw-r--r-- 2,050 bytes parent folder | download | duplicates (2)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**********************************************************************
 *
 * GEOS - Geometry Engine Open Source
 * http://geos.osgeo.org
 *
 * Copyright (C) 2019 Daniel Baston <dbaston@gmail.com>
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the GNU Lesser General Public Licence as published
 * by the Free Software Foundation.
 * See the COPYING file for more information.
 *
 **********************************************************************/

#include <geos/triangulate/DelaunayTriangulationBuilder.h>
#include <geos/triangulate/VoronoiDiagramBuilder.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/profiler.h>

#include <algorithm>
#include <random>
#include <vector>
#include <memory>

class SegmentUnaryUnionPerfTest {

public:
    void test(std::size_t num_lines) {
        using namespace geos::geom;

        std::default_random_engine e(12345);
        std::uniform_real_distribution<> dis(0, 100);


        std::vector<std::unique_ptr<LineString>> lines;

        for (std::size_t i = 0; i < num_lines; i++) {
            CoordinateSequence cas(2, 2);
            cas.setAt(Coordinate(dis(e), dis(e)), 0);
            cas.setAt(Coordinate(dis(e), dis(e)), 1);

            lines.emplace_back(gfact->createLineString(std::move(cas)));
        }

        auto g = gfact->createMultiLineString(std::move(lines));

        auto sw = profiler->get("union");
        sw->start();

        g->Union();

        sw->stop();

        std::cout << *sw << std::endl;
    }
private:
    decltype(geos::geom::GeometryFactory::create()) gfact = geos::geom::GeometryFactory::create();
    geos::util::Profiler* profiler = geos::util::Profiler::instance();
};

int main(int argc, char** argv) {
    SegmentUnaryUnionPerfTest tester;

    auto num_lines = std::atol(argv[1]);
    auto num_reps = argc > 2 ? std::atol(argv[2]) : 1;

    for (decltype(num_reps) i = 0; i < num_reps; i++) {
        tester.test(static_cast<std::size_t>(num_lines));
    }
}