File: LineIntersectorPerfTest.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 (97 lines) | stat: -rw-r--r-- 2,814 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**********************************************************************
 *
 * GEOS - Geometry Engine Open Source
 * http://geos.osgeo.org
 *
 * Copyright (C) 2021 Daniel Baston
 *
 * 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 <benchmark/benchmark.h>

#include <geos/algorithm/LineIntersector.h>
#include <geos/geom/Envelope.h>

#include <BenchmarkUtils.h>

#include <array>
#include <random>

using geos::geom::Coordinate;
using geos::geom::CoordinateXY;
using geos::geom::CoordinateXYM;
using geos::geom::CoordinateXYZM;
using geos::geom::CoordinateSequence;
using geos::geom::Envelope;
using geos::algorithm::LineIntersector;

template<typename CoordType>
static void BM_PointIntersection(benchmark::State& state) {
    unsigned int n = 1000;
    unsigned int seed = 12345;

    std::default_random_engine e(seed);

    std::array<Envelope, 4> envelopes {
        Envelope{-1, 0, 0, 1},  // NW
        Envelope{0, 1, 0, 1},   // NE
        Envelope{-1, 0, -1, 0}, // SW
        Envelope{0, 1, -1, 0}   // SE
    };

    std::array<CoordinateSequence, 4> pts;
    for (std::size_t i = 0; i < envelopes.size(); i++) {
        pts[i] = *geos::benchmark::createRandomCoords(envelopes[i], n, e);
    }

    LineIntersector li;
    std::size_t i = 0;
    for (auto _ : state) {
        const auto& p1 = pts[0].getAt<CoordType>(i);
        const auto& p2 = pts[2].getAt<CoordType>(i);
        const auto& q1 = pts[1].getAt<CoordType>(i);
        const auto& q2 = pts[3].getAt<CoordType>(i);

        li.computeIntersection(p1, p2, q1, q2);
        li.computeIntersection(p2, p1, q2, q1);
        li.computeIntersection(q2, p1, p2, q1);
        li.computeIntersection(q1, p1, p2, q2);

        i++;
        if (i > n) {
            i = 0;
        }
    }
}

template<typename CoordType>
static void BM_Collinear(benchmark::State& state) {
    CoordinateXYZM p1_xyzm(10, 10, 1, 8);
    CoordinateXYZM p2_xyzm(20, 10, 2, 8);
    CoordinateXYZM q1_xyzm(22, 10, 3, 9);
    CoordinateXYZM q2_xyzm(30, 10, 4, 11);

    CoordType p1(p1_xyzm);
    CoordType p2(p2_xyzm);
    CoordType q1(q1_xyzm);
    CoordType q2(q2_xyzm);

    for (auto _ : state) {
        LineIntersector li;
        li.computeIntersection(p1, p2, q1, q2);
    }
}
BENCHMARK_TEMPLATE(BM_PointIntersection, CoordinateXY);
BENCHMARK_TEMPLATE(BM_PointIntersection, Coordinate);
BENCHMARK_TEMPLATE(BM_PointIntersection, CoordinateXYZM);
BENCHMARK_TEMPLATE(BM_Collinear, CoordinateXY);
BENCHMARK_TEMPLATE(BM_Collinear, Coordinate);
BENCHMARK_TEMPLATE(BM_Collinear, CoordinateXYZM);

BENCHMARK_MAIN();