diff --git a/Linear_cell_complex/benchmark/Linear_cell_complex_2/CMakeLists.txt b/Linear_cell_complex/benchmark/Linear_cell_complex_2/CMakeLists.txt index 7c4998cafb6..195d30d3ba0 100644 --- a/Linear_cell_complex/benchmark/Linear_cell_complex_2/CMakeLists.txt +++ b/Linear_cell_complex/benchmark/Linear_cell_complex_2/CMakeLists.txt @@ -16,7 +16,7 @@ include_directories(BEFORE "/usr/include/libxml2/") #add_compile_definitions("-pg") #SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") # add_compile_definitions("-g") - +return() # OpenMesh find_package(OpenMesh REQUIRED) include(CGAL_OpenMesh_support) diff --git a/Linear_cell_complex/benchmark/Linear_cell_complex_3/CMakeLists.txt b/Linear_cell_complex/benchmark/Linear_cell_complex_3/CMakeLists.txt index 5166eee35ab..0a74b036673 100644 --- a/Linear_cell_complex/benchmark/Linear_cell_complex_3/CMakeLists.txt +++ b/Linear_cell_complex/benchmark/Linear_cell_complex_3/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.12...3.29) project(LCC_performance_3) +return() + if(NOT POLICY CMP0070 AND POLICY CMP0053) # Only set CMP0053 to OLD with CMake<3.10, otherwise there is a warning. cmake_policy(SET CMP0053 OLD) diff --git a/Polyline_simplification_2/benchmark/Polyline_simplification_2/CMakeLists.txt b/Polyline_simplification_2/benchmark/Polyline_simplification_2/CMakeLists.txt new file mode 100644 index 00000000000..5c6747a2883 --- /dev/null +++ b/Polyline_simplification_2/benchmark/Polyline_simplification_2/CMakeLists.txt @@ -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) diff --git a/Polyline_simplification_2/benchmark/Polyline_simplification_2/benchmark_simplify.cpp b/Polyline_simplification_2/benchmark/Polyline_simplification_2/benchmark_simplify.cpp new file mode 100644 index 00000000000..6b78ba89142 --- /dev/null +++ b/Polyline_simplification_2/benchmark/Polyline_simplification_2/benchmark_simplify.cpp @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace PS = CGAL::Polyline_simplification_2; + +using K = CGAL::Exact_predicates_inexact_constructions_kernel; +using Polygon_2 = CGAL::Polygon_2; +using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2; + +using Vb = PS::Vertex_base_2; +using Fb = CGAL::Constrained_triangulation_face_base_2; +using TDS = CGAL::Triangulation_data_structure_2; +using CDT = CGAL::Constrained_Delaunay_triangulation_2; +using CT = CGAL::Constrained_triangulation_plus_2; +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; + + using LineString = std::vector; + using MultiLineString = std::deque; + + using Polygon_2 = CGAL::Polygon_2; + using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2; + using MultiPolygon = std::deque; + + 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(); +}