[geos-commits] [SCM] GEOS branch main-relate-ng updated. 5b160a0354e49e56d23acbc755a46a69dabdbe76

git at osgeo.org git at osgeo.org
Wed Aug 7 08:38:53 PDT 2024


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, main-relate-ng has been updated
       via  5b160a0354e49e56d23acbc755a46a69dabdbe76 (commit)
      from  9c8b1f05712a54979879a46107fa23c87d8facb9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5b160a0354e49e56d23acbc755a46a69dabdbe76
Author: Martin Davis <mtnclimb at gmail.com>
Date:   Wed Aug 7 08:38:29 2024 -0700

    Add contains option to perf test

diff --git a/benchmarks/geom/PreparedPolygonIntersectsPerfTest.cpp b/benchmarks/geom/PreparedPolygonIntersectsPerfTest.cpp
index f04583831..f66ee0d10 100644
--- a/benchmarks/geom/PreparedPolygonIntersectsPerfTest.cpp
+++ b/benchmarks/geom/PreparedPolygonIntersectsPerfTest.cpp
@@ -1,3 +1,9 @@
+/******************************************************
+ *   Performance tests for spatial predicates
+ * 
+ * Usage: perf_prepared_polygon_intersects [ intersects | contains ]
+******************************************************/
+
 #include <geos/geom/util/SineStarFactory.h>
 #include <geos/geom/GeometryFactory.h>
 #include <geos/profiler.h>
@@ -16,52 +22,83 @@ std::size_t MAX_ITER = 10;
 std::size_t NUM_LINES = 10000;
 std::size_t NUM_LINES_PTS = 100;
 
+#define INTERSECTS 0
+#define CONTAINS 1
 
-int testRelateOp(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& lines) {
+int predicateOp = INTERSECTS;
+
+int testRelateOpIntersects(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& geoms) {
     int count = 0;
-    for (const auto& line : lines) {
-        auto im = g.relate(line.get());
+    for (const auto& geom : geoms) {
+        auto im = g.relate(geom.get());
         count += im->isIntersects();
     }
     return count;
 }
 
-int testGeometryIntersects(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& lines) {
+int testRelateOpContains(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& geoms) {
     int count = 0;
-    for (const auto& line : lines) {
-        count += g.intersects(line.get());
+    for (const auto& geom : geoms) {
+        auto im = g.relate(geom.get());
+        count += im->isContains();
     }
     return count;
 }
 
-int testGeometryContains(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& lines) {
+int testGeometryIntersects(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& geoms) {
     int count = 0;
-    for (const auto& line : lines) {
-        count += g.contains(line.get());
+    for (const auto& geom : geoms) {
+        count += g.intersects(geom.get());
     }
     return count;
 }
 
-int testPrepGeomCached(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& lines) {
+int testGeometryContains(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& geoms) {
+    int count = 0;
+    for (const auto& geom : geoms) {
+        count += g.contains(geom.get());
+    }
+    return count;
+}
+
+int testPrepGeomIntersects(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& geoms) {
     int count = 0;
     auto prep = prep::PreparedGeometryFactory::prepare(&g);
-    for (const auto& line : lines) {
-        count += prep->intersects(line.get());
+    for (const auto& geom : geoms) {
+        count += prep->intersects(geom.get());
     }
     return count;
 }
 
-int testRelateNGPreparedCached(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& lines) {
+int testPrepGeomContains(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& geoms) {
+    int count = 0;
+    auto prep = prep::PreparedGeometryFactory::prepare(&g);
+    for (const auto& geom : geoms) {
+        count += prep->contains(geom.get());
+    }
+    return count;
+}
+
+int testRelateNGPreparedIntersects(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& geoms) {
     int count = 0;
     auto prep = geos::operation::relateng::RelateNG::prepare(&g);
-    for (const auto& line : lines) {
+    for (const auto& line : geoms) {
         count += prep->evaluate(line.get(), *geos::operation::relateng::RelatePredicate::intersects());
     }
     return count;
 }
 
+int testRelateNGPreparedContains(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& geoms) {
+    int count = 0;
+    auto prep = geos::operation::relateng::RelateNG::prepare(&g);
+    for (const auto& line : geoms) {
+        count += prep->evaluate(line.get(), *geos::operation::relateng::RelatePredicate::contains());
+    }
+    return count;
+}
+
 template<typename F>
-double test(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& geoms, const std::string& method, F&& fun, double base)
+double test(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& geoms, const std::string& method, F&& fun, double baseTime)
 {
     geos::util::Profile sw("PreparedPolygonIntersects");
     sw.start();
@@ -73,7 +110,7 @@ double test(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& geo
 
     sw.stop();
     double tot = sw.getTot();
-    double timesFaster = base == 0 ? 1 : base / tot;
+    double timesFaster = baseTime == 0 ? 1 : baseTime / tot;
     std::cout << std::fixed << std::setprecision(0);
     std::cout << g.getNumPoints() << "," 
         << MAX_ITER * geoms.size() << "," 
@@ -86,38 +123,60 @@ double test(const Geometry& g, const std::vector<std::unique_ptr<Geometry>>& geo
     return tot;
 }
 
-void test (std::size_t npts) {
+void test(int dim, std::size_t npts) {
 
     auto target = geos::benchmark::createSineStar({0, 0}, 100, npts);
-    auto polygons = geos::benchmark::createPolygons(*target->getEnvelopeInternal(), NUM_LINES, 1.0, NUM_LINES_PTS);
-    auto lines = geos::benchmark::createLines(*target->getEnvelopeInternal(), NUM_LINES, 1.0, NUM_LINES_PTS);
-    auto points = geos::benchmark::createPoints(*target->getEnvelopeInternal(), NUM_LINES);
-
-    double base;
-    base = test(*target, polygons, "RelateOp", testRelateOp, 0);
-    test(*target, polygons, "Geometry::intersects", testGeometryIntersects, base);
-    test(*target, polygons, "PrepGeomCached", testPrepGeomCached, base);
-    test(*target, polygons, "RelateNGPreparedCached", testRelateNGPreparedCached, base);
-
-    base = test(*target, lines, "RelateOp", testRelateOp, 0);
-    test(*target, lines, "Geometry::intersects", testGeometryIntersects, base);
-    test(*target, lines, "PrepGeomCached", testPrepGeomCached, base);
-    test(*target, lines, "RelateNGPreparedCached", testRelateNGPreparedCached, base);
-
-    base = test(*target, points, "RelateOp", testRelateOp, 0);
-    test(*target, points, "Geometry::intersects", testGeometryIntersects, base);
-    test(*target, points, "PrepGeomCached", testPrepGeomCached, base);
-    test(*target, points, "RelateNGPreparedCached", testRelateNGPreparedCached, base);
+    std::vector<std::unique_ptr<Geometry>> geoms;
+    switch (dim) {
+    case 0:
+        geoms = geos::benchmark::createPoints(*target->getEnvelopeInternal(), NUM_LINES);
+        break;
+    case 1:
+        geoms = geos::benchmark::createLines(*target->getEnvelopeInternal(), NUM_LINES, 1.0, NUM_LINES_PTS);
+        break;
+    case 2:
+        geoms = geos::benchmark::createPolygons(*target->getEnvelopeInternal(), NUM_LINES, 1.0, NUM_LINES_PTS);
+        break;
+    }
+    double baseTime;
+    switch (predicateOp) {
+    case INTERSECTS:
+        baseTime = test(*target, geoms, "RelateOp intersects", testRelateOpIntersects, 0);
+        test(*target, geoms, "Geometry::intersects", testGeometryIntersects, baseTime);
+        test(*target, geoms, "PreparedGeom", testPrepGeomIntersects, baseTime);
+        test(*target, geoms, "RelateNGPrepared", testRelateNGPreparedIntersects, baseTime);
+        break;
+    case CONTAINS:
+        baseTime = test(*target, geoms, "RelateOp contains", testRelateOpIntersects, 0);
+        test(*target, geoms, "Geometry::contains", testGeometryIntersects, baseTime);
+        test(*target, geoms, "PreparedGeom contains", testPrepGeomContains, baseTime);
+        test(*target, geoms, "RelateNGPrepared contains", testRelateNGPreparedContains, baseTime);
+    }
 }
 
-int main() {
+void testAll(int dim)
+{
+    test(dim, 5);
+    test(dim, 10);
+    test(dim, 500);
+    test(dim, 1000);
+    test(dim, 2000);
+    test(dim, 4000);
+    test(dim, 8000);
+    test(dim, 16000);
+}
+
+int main(int argc, char** argv) {
+    predicateOp = INTERSECTS;
+    if (argc >= 2) {
+        std::string op{argv[1]};
+        if (op == "contains") {
+            predicateOp = CONTAINS;
+        }
+    }
+
     std::cout << "target_points,num_tests,num_hits,test_type,pts_in_test,method,time,factor" << std::endl;
-    test(5);
-    test(10);
-    test(500);
-    test(1000);
-    test(2000);
-    test(4000);
-    test(8000);
-    test(16000);
+    testAll(0);
+    testAll(1);
+    testAll(2);
 }

-----------------------------------------------------------------------

Summary of changes:
 .../geom/PreparedPolygonIntersectsPerfTest.cpp     | 149 ++++++++++++++-------
 1 file changed, 104 insertions(+), 45 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list