add a benchmark for Polyline_simplification_2

Using the tool `compare.py` from [Google Benchmark Tools][1]...

[1]: https://github.com/google/benchmark/blob/main/docs/tools.md

...given that:

  - `benchmark_simplify-AFTER` is the file `benchmark_simplify.cpp`
    compiled from this branch, and flags `-msse3  -DNDEBUG -O3`
    with gcc version 14.2.1,
  - `benchmark_simplify-BEFORE` is the same file
    compiled from the branch `master`, and same flags and compiler.

the command line was:

```shell
compare.py benchmarks build/Release/benchmark/Polyline_simplification_2/benchmark_simplify-BEFORE build/Release/benchmark/Polyline_simplification_2/benchmark_simplify-AFTER Data/data/wkt/norway-MP.wkt --benchmark_repetitions=20 --benchmark_counters_tabular=true --benchmark_time_unit=s
```

The following results show that there is a speedup
of about 15% (mean) or 18% (median)

```
RUNNING: build/Release/benchmark/Polyline_simplification_2/benchmark_simplify-BEFORE Data/data/wkt/norway-MP.wkt --benchmark_repetitions=20 --benchmark_counters_tabular=true --benchmark_time_unit=s --benchmark_out=/tmp/tmpvxyq_i24
2025-02-06T17:23:08+01:00
Running Data/data/wkt/norway-MP.wkt
Run on (16 X 800 MHz CPU s)
CPU Caches:
  L1 Data 48 KiB (x8)
  L1 Instruction 32 KiB (x8)
  L2 Unified 1280 KiB (x8)
  L3 Unified 24576 KiB (x1)
Load Average: 1.47, 2.07, 1.65
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Benchmark                                                 Time             CPU   Iterations    #points  #polygons #polylines nb of constraints nb of sub-constraints nb of vertices
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
simplify file Data/data/wkt/norway-MP.wkt             0.067 s         0.067 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.066 s         0.066 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.065 s         0.065 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.073 s         0.072 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.066 s         0.066 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.064 s         0.064 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.067 s         0.066 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.071 s         0.071 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.064 s         0.064 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.064 s         0.064 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.074 s         0.074 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.066 s         0.066 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.075 s         0.074 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.074 s         0.074 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.076 s         0.076 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.078 s         0.078 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.074 s         0.074 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.067 s         0.067 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.064 s         0.064 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.069 s         0.069 s            12          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt_mean        0.069 s         0.069 s            20          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt_median      0.067 s         0.067 s            20          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt_stddev      0.005 s         0.005 s            20          0          0          0                 0                     0              0
simplify file Data/data/wkt/norway-MP.wkt_cv           6.73 %          6.68 %            20      0.00%      0.00%      0.00%             0.00%                 0.00%          0.00%
RUNNING: build/Release/benchmark/Polyline_simplification_2/benchmark_simplify-AFTER Data/data/wkt/norway-MP.wkt --benchmark_repetitions=20 --benchmark_counters_tabular=true --benchmark_time_unit=s --benchmark_out=/tmp/tmp59ui0dsw
2025-02-06T17:29:26+01:00
Running Data/data/wkt/norway-MP.wkt
Run on (16 X 800.961 MHz CPU s)
CPU Caches:
  L1 Data 48 KiB (x8)
  L1 Instruction 32 KiB (x8)
  L2 Unified 1280 KiB (x8)
  L3 Unified 24576 KiB (x1)
Load Average: 1.61, 1.94, 1.73
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Benchmark                                                 Time             CPU   Iterations    #points  #polygons #polylines nb of constraints nb of sub-constraints nb of vertices
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
simplify file Data/data/wkt/norway-MP.wkt             0.054 s         0.054 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.057 s         0.057 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.059 s         0.059 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.065 s         0.065 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.058 s         0.058 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.056 s         0.056 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.053 s         0.053 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.061 s         0.061 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.058 s         0.058 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.052 s         0.052 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.054 s         0.054 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.055 s         0.054 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.054 s         0.054 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.055 s         0.054 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.054 s         0.054 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.059 s         0.059 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.057 s         0.057 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.058 s         0.057 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.055 s         0.055 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt             0.059 s         0.059 s            13          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt_mean        0.057 s         0.057 s            20          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt_median      0.057 s         0.056 s            20          0        848          0               849               40.568k        40.565k
simplify file Data/data/wkt/norway-MP.wkt_stddev      0.003 s         0.003 s            20          0          0          0                 0                     0              0
simplify file Data/data/wkt/norway-MP.wkt_cv           5.37 %          5.32 %            20      0.00%      0.00%      0.00%             0.00%                 0.00%          0.00%
Comparing build/Release/benchmark/Polyline_simplification_2/benchmark_simplify-BEFORE to build/Release/benchmark/Polyline_simplification_2/benchmark_simplify-AFTER
Benchmark                                                          Time             CPU      Time Old      Time New       CPU Old       CPU New
-----------------------------------------------------------------------------------------------------------------------------------------------
simplify file Data/data/wkt/norway-MP.wkt                       -0.1941         -0.1942             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1269         -0.1272             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.0900         -0.0918             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1049         -0.1065             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1204         -0.1206             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1279         -0.1282             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1962         -0.1961             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1370         -0.1377             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.0951         -0.0962             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1851         -0.1852             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.2720         -0.2716             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1702         -0.1717             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.2700         -0.2703             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.2644         -0.2634             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.2861         -0.2856             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.2492         -0.2488             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.2310         -0.2301             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1382         -0.1389             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1401         -0.1406             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt                       -0.1464         -0.1467             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt_pvalue                 0.0000          0.0000      U Test, Repetitions: 20 vs 20
simplify file Data/data/wkt/norway-MP.wkt_mean                  -0.1804         -0.1806             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt_median                -0.1547         -0.1549             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt_stddev                -0.3458         -0.3479             0             0             0             0
simplify file Data/data/wkt/norway-MP.wkt_cv                    -0.2018         -0.2041             0             0             0             0
OVERALL_GEOMEAN                                                 -0.1797         -0.1800             0             0             0             0
```
This commit is contained in:
Laurent Rineau 2025-02-06 17:08:54 +01:00
parent 765744e8b2
commit bc44c91536
4 changed files with 112 additions and 1 deletions

View File

@ -16,7 +16,7 @@ include_directories(BEFORE "/usr/include/libxml2/")
#add_compile_definitions("-pg") #add_compile_definitions("-pg")
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") #SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
# add_compile_definitions("-g") # add_compile_definitions("-g")
return()
# OpenMesh # OpenMesh
find_package(OpenMesh REQUIRED) find_package(OpenMesh REQUIRED)
include(CGAL_OpenMesh_support) include(CGAL_OpenMesh_support)

View File

@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.12...3.29) cmake_minimum_required(VERSION 3.12...3.29)
project(LCC_performance_3) project(LCC_performance_3)
return()
if(NOT POLICY CMP0070 AND POLICY CMP0053) if(NOT POLICY CMP0070 AND POLICY CMP0053)
# Only set CMP0053 to OLD with CMake<3.10, otherwise there is a warning. # Only set CMP0053 to OLD with CMake<3.10, otherwise there is a warning.
cmake_policy(SET CMP0053 OLD) cmake_policy(SET CMP0053 OLD)

View File

@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.12...3.29)
project(Polyline_simplification_2_Benchmarks)
# Add Google Benchmark
find_package(benchmark REQUIRED)
# Add CGAL
find_package(CGAL REQUIRED)
add_executable(benchmark_simplify benchmark_simplify.cpp)
target_link_libraries(benchmark_simplify PRIVATE benchmark::benchmark CGAL::CGAL CGAL::Data)

View File

@ -0,0 +1,98 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Constrained_triangulation_plus_2.h>
#include <CGAL/Polyline_simplification_2/simplify.h>
#include <CGAL/Polyline_simplification_2/Squared_distance_cost.h>
#include <CGAL/IO/WKT.h>
#include <benchmark/benchmark.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <deque>
namespace PS = CGAL::Polyline_simplification_2;
using K = CGAL::Exact_predicates_inexact_constructions_kernel;
using Polygon_2 = CGAL::Polygon_2<K>;
using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2<K>;
using Vb = PS::Vertex_base_2<K>;
using Fb = CGAL::Constrained_triangulation_face_base_2<K>;
using TDS = CGAL::Triangulation_data_structure_2<Vb, Fb>;
using CDT = CGAL::Constrained_Delaunay_triangulation_2<K, TDS, CGAL::Exact_predicates_tag>;
using CT = CGAL::Constrained_triangulation_plus_2<CDT>;
using Stop = PS::Stop_below_count_ratio_threshold;
using Cost = PS::Squared_distance_cost;
static void BM_Simplify(benchmark::State& state, std::string filename) {
using Point_2 = K::Point_2;
using MultiPoint = std::vector<Point_2>;
using LineString = std::vector<Point_2>;
using MultiLineString = std::deque<LineString>;
using Polygon_2 = CGAL::Polygon_2<K>;
using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2<K>;
using MultiPolygon = std::deque<Polygon_with_holes_2>;
std::ifstream ifs(filename);
MultiPoint points;
MultiLineString polylines;
MultiPolygon polygons;
if(!CGAL::IO::read_WKT(ifs, points, polylines, polygons) && false) {
state.SkipWithError("Cannot read file " + filename);
return;
}
state.counters["#points"] = points.size();
state.counters["#polylines"] = polylines.size();
state.counters["#polygons"] = polygons.size();
CT ct;
for(const auto& point : points) {
ct.insert(point);
}
for(const auto& polyline : polylines) {
ct.insert_constraint(polyline);
}
for(const auto& polygon_with_holes : polygons) {
const Polygon_2& outer_polygon = polygon_with_holes.outer_boundary();
ct.insert_constraint(outer_polygon);
for(Polygon_with_holes_2::Hole_const_iterator it = polygon_with_holes.holes_begin();
it != polygon_with_holes.holes_end(); ++it)
{
const Polygon_2& hole = *it;
ct.insert_constraint(hole);
}
}
state.counters["nb of constraints"] = ct.number_of_constraints();
state.counters["nb of vertices"] = ct.number_of_vertices();
state.counters["nb of sub-constraints"] = ct.number_of_subconstraints();
for([[maybe_unused]] auto _ : state) {
state.PauseTiming();
CT ct_copy = ct; // Copy the object `ct` in the loop
state.ResumeTiming();
PS::simplify(ct_copy, Cost(), Stop(0.5));
}
}
int main(int argc, char** argv) {
std::string filename = CGAL::data_file_path("wkt/norway-MP.wkt");
if(argc > 1) {
std::string_view arg1{argv[1]};
if(arg1.size() < 2 || arg1[0] != '-' || arg1[1] != '-') {
--argc;
++argv;
filename = arg1;
}
}
benchmark::RegisterBenchmark("simplify file " + filename, BM_Simplify, filename);
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
benchmark::Shutdown();
}