Skip to content

Commit

Permalink
Implement nearest neighbor benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Aug 29, 2020
1 parent a868a82 commit b1d1e54
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
43 changes: 40 additions & 3 deletions Octree/benchmark/Octree/nearest_neighbor.cpp
@@ -1,23 +1,60 @@

#define CGAL_TRACE_STREAM std::cerr

#include "util.h"

#include <CGAL/Octree.h>

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>

#include <iostream>
#include <fstream>
#include <chrono>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;
typedef CGAL::Point_set_3<Point> Point_set;

typedef CGAL::Octree::Octree<Point_set, typename Point_set::Point_map> Octree;

using std::chrono::high_resolution_clock;
using std::chrono::duration_cast;
using std::chrono::microseconds;

int main(int argc, char **argv) {

// 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";

for (size_t num_points = 10; num_points < 10000; num_points *= 1.1) {
// Perform tests for various dataset sizes
for (size_t num_points = 10; num_points < 1000000; num_points *= 1.1) {

// Create a collection of the right number of points
auto points = generate<Kernel>(num_points);

// Create a search point
auto search_point = *generate<Kernel>().points().begin();

// Build the tree (not timed)
Octree octree(points, points.point_map());
octree.refine();

// Start the timer
auto start = high_resolution_clock::now();

// Find the nearest point to the search point
std::vector<Point> nearest_neighbors;
octree.nearest_k_neighbors(search_point, 10, std::back_inserter(nearest_neighbors));

std::cout << num_points << std::endl;
// End the timer
auto end = high_resolution_clock::now();

file << num_points << ",";
file << 5 << "\n";
file << duration_cast<microseconds>(end - start).count() << "\n";
}

file.close();
Expand Down
2 changes: 1 addition & 1 deletion Octree/benchmark/Octree/util.h
Expand Up @@ -6,7 +6,7 @@
#include <CGAL/point_generators_3.h>

template<class Kernel>
CGAL::Point_set_3<typename Kernel::Point_3> generate(size_t num_points) {
CGAL::Point_set_3<typename Kernel::Point_3> generate(size_t num_points = 1) {

typedef typename Kernel::Point_3 Point;
typedef CGAL::Point_set_3<Point> Point_set;
Expand Down

0 comments on commit b1d1e54

Please sign in to comment.