diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index c73a786c28a..bf353c70f90 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -23,6 +23,11 @@ PCL_ADD_BENCHMARK(filters_voxel_grid FILES filters/voxel_grid.cpp ARGUMENTS "${PCL_SOURCE_DIR}/test/table_scene_mug_stereo_textured.pcd" "${PCL_SOURCE_DIR}/test/milk_cartoon_all_small_clorox.pcd") +PCL_ADD_BENCHMARK(filters_radius_outlier_removal FILES filters/radius_outlier_removal.cpp + LINK_WITH pcl_io pcl_filters + ARGUMENTS "${PCL_SOURCE_DIR}/test/table_scene_mug_stereo_textured.pcd" + "${PCL_SOURCE_DIR}/test/milk_cartoon_all_small_clorox.pcd") + PCL_ADD_BENCHMARK(search_radius_search FILES search/radius_search.cpp LINK_WITH pcl_io pcl_search ARGUMENTS "${PCL_SOURCE_DIR}/test/table_scene_mug_stereo_textured.pcd" diff --git a/benchmarks/filters/radius_outlier_removal.cpp b/benchmarks/filters/radius_outlier_removal.cpp new file mode 100644 index 00000000000..66aa527d1a5 --- /dev/null +++ b/benchmarks/filters/radius_outlier_removal.cpp @@ -0,0 +1,84 @@ +#include +#include // for PCDReader + +#include + +static void +BM_RadiusOutlierRemoval(benchmark::State& state, const std::string& file) +{ + // Perform setup here + pcl::PointCloud::Ptr cloud(new pcl::PointCloud); + pcl::PCDReader reader; + reader.read(file, *cloud); + + pcl::RadiusOutlierRemoval ror; + ror.setInputCloud(cloud); + ror.setRadiusSearch(0.02); + ror.setMinNeighborsInRadius(14); + + pcl::PointCloud::Ptr cloud_voxelized( + new pcl::PointCloud); + for (auto _ : state) { + // This code gets timed + ror.filter(*cloud_voxelized); + } +} + +static void +BM_RadiusOutlierRemovalOpenMP(benchmark::State& state, const std::string& file) +{ + // Perform setup here + pcl::PointCloud::Ptr cloud(new pcl::PointCloud); + pcl::PCDReader reader; + reader.read(file, *cloud); + + pcl::RadiusOutlierRemoval ror; + ror.setInputCloud(cloud); + ror.setRadiusSearch(0.02); + ror.setMinNeighborsInRadius(14); + ror.setNumberOfThreads(0); + + pcl::PointCloud::Ptr cloud_voxelized( + new pcl::PointCloud); + for (auto _ : state) { + // This code gets timed + ror.filter(*cloud_voxelized); + } +} + +int +main(int argc, char** argv) +{ + constexpr int runs = 100; + + if (argc < 3) { + std::cerr + << "No test files given. Please download `table_scene_mug_stereo_textured.pcd` " + "and `milk_cartoon_all_small_clorox.pcd`, and pass their paths to the test." + << std::endl; + return (-1); + } + + benchmark::RegisterBenchmark( + "BM_RadiusOutlierRemoval_milk", &BM_RadiusOutlierRemoval, argv[2]) + ->Unit(benchmark::kMillisecond) + ->Iterations(runs); + + benchmark::RegisterBenchmark( + "BM_RadiusOutlierRemoval_mug", &BM_RadiusOutlierRemoval, argv[1]) + ->Unit(benchmark::kMillisecond) + ->Iterations(runs); + + benchmark::RegisterBenchmark( + "BM_RadiusOutlierRemovalOpenMP_milk", &BM_RadiusOutlierRemovalOpenMP, argv[2]) + ->Unit(benchmark::kMillisecond) + ->Iterations(runs); + + benchmark::RegisterBenchmark( + "BM_RadiusOutlierRemovalOpenMP_mug", &BM_RadiusOutlierRemovalOpenMP, argv[1]) + ->Unit(benchmark::kMillisecond) + ->Iterations(runs); + + benchmark::Initialize(&argc, argv); + benchmark::RunSpecifiedBenchmarks(); +}