File: CoverageUnionPerfTest.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 (65 lines) | stat: -rw-r--r-- 1,973 bytes parent folder | download
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
/**********************************************************************
 *
 * GEOS - Geometry Engine Open Source
 * http://geos.osgeo.org
 *
 * Copyright (C) 2025 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 <stdexcept>
#include <benchmark/benchmark.h>

#include <BenchmarkUtils.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/Geometry.h>
#include <geos/coverage/CoverageUnion.h>
#include <geos/operation/union/CoverageUnion.h>

struct SegmentSet {
    static void Union(const geos::geom::GeometryCollection& coll) {
        geos::operation::geounion::CoverageUnion::Union(&coll);
    }
};

struct BoundaryChain {
    static void Union(const geos::geom::GeometryCollection& coll) {
        auto result = geos::coverage::CoverageUnion::Union(&coll);
    }
};

template<typename Impl>
static void BM_CoverageUnion(benchmark::State& state) {
    const auto& gfact = *geos::geom::GeometryFactory::getDefaultInstance();

    auto nCells = state.range(0);

    auto nx = static_cast<int>(std::ceil(std::sqrt(nCells)));
    auto ny = static_cast<int>(std::ceil(std::sqrt(nCells)));

    nCells = nx*ny;

    geos::geom::Envelope env(0, nx, 0, ny);

    auto cells = geos::benchmark::createGeometriesOnGrid(env, static_cast<std::size_t>(nCells), [&gfact](const auto& base) {
        geos::geom::Envelope box(base.x, base.x + 1, base.y, base.y + 1);
        return gfact.toGeometry(&box);
    });

    auto coll = gfact.createGeometryCollection(std::move(cells));

    for (auto _ : state) {
        Impl::Union(*coll);
    }
}

BENCHMARK_TEMPLATE(BM_CoverageUnion, SegmentSet)->Range(1000, 1000000);
BENCHMARK_TEMPLATE(BM_CoverageUnion, BoundaryChain)->Range(1000, 1000000);

BENCHMARK_MAIN();