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
|
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2024 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 <BenchmarkUtils.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/Geometry.h>
#include <geos/operation/distance/DistanceOp.h>
using geos::operation::distance::DistanceOp;
static void BM_PointPointDistance(benchmark::State& state) {
geos::geom::Envelope e(-100, 100, -100, 100);
auto points = geos::benchmark::createPoints(e, 100000);
for (auto _ : state) {
for (std::size_t i = 0; i < points.size(); i++) {
for (std::size_t j = 0; i < points.size(); i++) {
points[i]->distance(points[j].get());
}
}
}
}
static void BM_PointLineDistance(benchmark::State& state) {
geos::geom::Envelope e(-100, 100, -100, 100);
auto points = geos::benchmark::createPoints(e, 1000);
std::size_t points_per_line = 30;
std::size_t nlines = 100;
double line_size = e.getWidth() / static_cast<double>(nlines * nlines);
auto lines = geos::benchmark::createLines(e, nlines, line_size, points_per_line);
for (auto _ : state) {
for (const auto& line : lines) {
for (const auto& point : points) {
line->distance(point.get());
}
}
}
}
static void BM_LineLineDistance(benchmark::State& state) {
geos::geom::Envelope e(-100, 100, -100, 100);
std::size_t points_per_line = 30;
std::size_t nlines = 100;
double line_size = e.getWidth() / static_cast<double>(nlines * nlines);
auto lines = geos::benchmark::createLines(e, nlines, line_size, points_per_line);
for (auto _ : state) {
for (const auto& line1 : lines) {
for (const auto& line2 : lines) {
line1->distance(line2.get());
}
}
}
}
BENCHMARK(BM_PointPointDistance);
BENCHMARK(BM_PointLineDistance);
BENCHMARK(BM_LineLineDistance);
BENCHMARK_MAIN();
|