diff --git a/Orthtree/benchmark/Orthtree/construction.cpp b/Orthtree/benchmark/Orthtree/construction.cpp index a82984c9353..ca7c5100003 100644 --- a/Orthtree/benchmark/Orthtree/construction.cpp +++ b/Orthtree/benchmark/Orthtree/construction.cpp @@ -10,7 +10,6 @@ #include #include -#include #include typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; diff --git a/Orthtree/benchmark/Orthtree/nearest_neighbor.cpp b/Orthtree/benchmark/Orthtree/nearest_neighbor.cpp index d83166d0c56..5be9f286b68 100644 --- a/Orthtree/benchmark/Orthtree/nearest_neighbor.cpp +++ b/Orthtree/benchmark/Orthtree/nearest_neighbor.cpp @@ -3,12 +3,13 @@ #include "util.h" -#include - #include +#include +#include +#include + #include -#include #include typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; @@ -18,21 +19,30 @@ typedef Point_set::Point_map Point_map; typedef CGAL::Octree Octree; +typedef CGAL::Search_traits_3 Kd_tree_traits; +typedef CGAL::Orthogonal_k_neighbor_search Kd_tree_search; +typedef Kd_tree_search::Tree Kdtree; + using std::chrono::high_resolution_clock; using std::chrono::duration_cast; using std::chrono::microseconds; int main(int argc, char **argv) { + size_t k = 10; + // Set output file std::ofstream file; file.open((argc > 1) ? argv[1] : "../nearest_neighbor_benchmark.csv"); // Add header for CSV - file << "Number of Points,Search Time (ms) \n"; + file << "Number of Points,Octree,kDTree \n"; // Perform tests for various dataset sizes - for (size_t num_points = 10; num_points < 1000000; num_points *= 1.1) { + for (size_t num_points = 100; num_points < 10000000; num_points *= 1.05) { + + file << num_points << ","; + std::cout << num_points << std::endl; // Create a collection of the right number of points auto points = generate(num_points); @@ -40,22 +50,34 @@ int main(int argc, char **argv) { // Create a search point auto search_point = *generate().points().begin(); - // Build the tree (not timed) - Octree octree(points, points.point_map()); - octree.refine(); + { + // Build the tree (not timed) + auto octreePoints = points; + Octree octree(octreePoints, octreePoints.point_map()); + octree.refine(); - auto elapsedTime = bench( - [&] { - // Find the nearest point to the search point - std::vector nearest_neighbors; - octree.nearest_neighbors(search_point, 10, std::back_inserter(nearest_neighbors)); - } - ); + auto octreeTime = bench( + [&] { + std::vector nearest_neighbors; + octree.nearest_neighbors(search_point, k, std::back_inserter(nearest_neighbors)); + } + ); + file << octreeTime.count() << ","; + } - file << num_points << ","; - file << elapsedTime.count() << "\n"; + { + auto kdtreePoints = points; + Kdtree kdtree(kdtreePoints.points().begin(), kdtreePoints.points().end()); + kdtree.build(); + + auto kdtreeTime = bench( + [&] { + Kd_tree_search search(kdtree, search_point, k); + } + ); + file << kdtreeTime.count() << "\n"; + } - std::cout << num_points << std::endl; } file.close(); diff --git a/Orthtree/benchmark/Orthtree/plot_construction_benchmark.p b/Orthtree/benchmark/Orthtree/plot_construction_benchmark.p index 8e4b403baf3..4bd6db976ce 100644 --- a/Orthtree/benchmark/Orthtree/plot_construction_benchmark.p +++ b/Orthtree/benchmark/Orthtree/plot_construction_benchmark.p @@ -10,7 +10,7 @@ set style data lines set title 'Time to construct a tree from points' set xlabel "Number of points" -set ylabel "Time (ms)" +set ylabel "Time (us)" set key autotitle columnhead set datafile separator "," diff --git a/Orthtree/benchmark/Orthtree/plot_nearest_neighbor_benchmark.p b/Orthtree/benchmark/Orthtree/plot_nearest_neighbor_benchmark.p new file mode 100644 index 00000000000..8dd49dca62b --- /dev/null +++ b/Orthtree/benchmark/Orthtree/plot_nearest_neighbor_benchmark.p @@ -0,0 +1,17 @@ + +reset + +set terminal png size 800,500 +set output 'nearest_neighbor_benchmark.png' + +set grid +set style data lines +#set logscale x + +set title 'Time to find the neighbors of a point using a tree' +set xlabel "Number of points" +set ylabel "Time (us)" +set key autotitle columnhead + +set datafile separator "," +plot for [col=2:3] 'nearest_neighbor_benchmark.csv' using 1:col