File: VoronoiPerfTest.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 (125 lines) | stat: -rw-r--r-- 4,115 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**********************************************************************
 *
 * 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>

#include <benchmark/benchmark.h>

#include <BenchmarkUtils.h>

using geos::geom::Coordinate;
using geos::geom::Envelope;

static void BM_DelaunayFromSeq(benchmark::State& state) {
    Envelope e(0, 100, 0, 100);
    auto gfact = geos::geom::GeometryFactory::getDefaultInstance();
    std::default_random_engine eng(12345);

    for (auto _ : state) {
        state.PauseTiming();
        auto nPts = static_cast<std::size_t>(state.range(0));
        auto sites = geos::benchmark::createRandomCoords(e, nPts, eng);
        state.ResumeTiming();

        geos::triangulate::DelaunayTriangulationBuilder dtb;
        dtb.setSites(*sites);
        auto result = dtb.getTriangles(*gfact);
    }
}

static void BM_DelaunayFromGeom(benchmark::State& state) {
    Envelope e(0, 100, 0, 100);
    auto gfact = geos::geom::GeometryFactory::getDefaultInstance();
    std::default_random_engine eng(12345);

    for (auto _ : state) {
        state.PauseTiming();
        auto nPts = static_cast<std::size_t>(state.range(0));
        auto sites = gfact->createLineString(geos::benchmark::createRandomCoords(e, nPts, eng));
        state.ResumeTiming();

        geos::triangulate::DelaunayTriangulationBuilder dtb;
        dtb.setSites(*sites);
        auto result = dtb.getTriangles(*gfact);
    }
}

static void BM_VoronoiFromSeq(benchmark::State& state) {
    Envelope e(0, 100, 0, 100);
    auto gfact = geos::geom::GeometryFactory::getDefaultInstance();
    std::default_random_engine eng(12345);

    for (auto _ : state) {
        state.PauseTiming();
        auto nPts = static_cast<std::size_t>(state.range(0));
        auto sites = geos::benchmark::createRandomCoords(e, nPts, eng);
        state.ResumeTiming();

        geos::triangulate::VoronoiDiagramBuilder vdb;
        vdb.setSites(*sites);
        auto result = vdb.getDiagram(*gfact);
    }
}

static void BM_VoronoiFromGeom(benchmark::State& state) {
    Envelope e(0, 100, 0, 100);
    auto gfact = geos::geom::GeometryFactory::getDefaultInstance();
    std::default_random_engine eng(12345);

    for (auto _ : state) {
        state.PauseTiming();
        auto nPts = static_cast<std::size_t>(state.range(0));
        auto sites = gfact->createLineString(geos::benchmark::createRandomCoords(e, nPts, eng));
        state.ResumeTiming();

        geos::triangulate::VoronoiDiagramBuilder vdb;
        vdb.setSites(*sites);
        auto result = vdb.getDiagram(*gfact);
    }
}

static void BM_OrderedVoronoiFromGeom(benchmark::State& state) {
    Envelope e(0, 100, 0, 100);
    auto gfact = geos::geom::GeometryFactory::getDefaultInstance();
    std::default_random_engine eng(12345);

    for (auto _ : state) {
        state.PauseTiming();
        auto nPts = static_cast<std::size_t>(state.range(0));
        auto sites = gfact->createLineString(geos::benchmark::createRandomCoords(e, nPts, eng));
        state.ResumeTiming();

        geos::triangulate::VoronoiDiagramBuilder vdb;
        vdb.setOrdered(true);
        vdb.setSites(*sites);
        auto result = vdb.getDiagram(*gfact);
    }
}

BENCHMARK(BM_DelaunayFromSeq)->Range(10, 1e6);
BENCHMARK(BM_DelaunayFromGeom)->Range(10, 1e6);
BENCHMARK(BM_VoronoiFromSeq)->Range(10, 1e6);
BENCHMARK(BM_VoronoiFromGeom)->Range(10, 1e6);
BENCHMARK(BM_OrderedVoronoiFromGeom)->Range(10, 1e6);

BENCHMARK_MAIN();