Skip to content

Commit f25fc5b

Browse files
committed
Single cloud benchmark unrealistic. Updated to use two.
1 parent 22f6bb6 commit f25fc5b

File tree

10 files changed

+190
-190
lines changed

10 files changed

+190
-190
lines changed

examples/benchmark/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ endif()
5151
add_executable(uosr_to_bin)
5252
target_sources(uosr_to_bin
5353
PRIVATE
54-
${CMAKE_CURRENT_LIST_DIR}/format_uosr.cpp
5554
${CMAKE_CURRENT_LIST_DIR}/uosr_to_bin.cpp
5655
)
5756
target_link_libraries(uosr_to_bin PRIVATE pico_toolshed)

examples/benchmark/benchmark.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ namespace pico_tree {
99
class Benchmark : public benchmark::Fixture {
1010
protected:
1111
using Index = int;
12-
using Scalar = double;
13-
using PointX = Point3d;
12+
using Scalar = float;
13+
using PointX = Point3f;
1414

1515
public:
1616
Benchmark() {
17-
// Here you may need to be patient. Depending on the size of the compiled
18-
// binary.
19-
pico_tree::ReadBin("./scans.bin", &points_);
17+
// Here you may need to be patient depending on the size of the binaries.
18+
// Loaded for each benchmark.
19+
pico_tree::ReadBin("./scans0.bin", &points_tree_);
20+
pico_tree::ReadBin("./scans1.bin", &points_test_);
2021
}
2122

2223
protected:
23-
std::vector<PointX> points_;
24+
std::vector<PointX> points_tree_;
25+
std::vector<PointX> points_test_;
2426
};
2527

2628
} // namespace pico_tree

examples/benchmark/bin_to_ascii.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int main() {
1515
std::cout << path_bin.string() << " doesn't exist." << std::endl;
1616
} else if (!std::filesystem::exists(path_ascii)) {
1717
std::cout << "Reading points in bin format..." << std::endl;
18-
std::vector<Point3d> points;
18+
std::vector<Point3f> points;
1919
pico_tree::ReadBin(path_bin.string(), &points);
2020
std::cout << "Read " << points.size() << " points." << std::endl;
2121
std::cout << "Writing points to ascii xyz format..." << std::endl;

examples/benchmark/bm_nanoflann.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class BmNanoflann : public pico_tree::Benchmark {
2626

2727
BENCHMARK_DEFINE_F(BmNanoflann, BuildCt)(benchmark::State& state) {
2828
int max_leaf_size = state.range(0);
29-
NanoAdaptorX adaptor(points_);
29+
NanoAdaptorX adaptor(points_tree_);
3030
for (auto _ : state) {
3131
NanoKdTreeCt<NanoAdaptorX> tree(
3232
PointX::Dim,
@@ -38,7 +38,7 @@ BENCHMARK_DEFINE_F(BmNanoflann, BuildCt)(benchmark::State& state) {
3838

3939
BENCHMARK_DEFINE_F(BmNanoflann, BuildRt)(benchmark::State& state) {
4040
int max_leaf_size = state.range(0);
41-
NanoAdaptorX adaptor(points_);
41+
NanoAdaptorX adaptor(points_tree_);
4242
for (auto _ : state) {
4343
NanoKdTreeRt<NanoAdaptorX> tree(
4444
PointX::Dim,
@@ -66,7 +66,7 @@ BENCHMARK_REGISTER_F(BmNanoflann, BuildRt)
6666
BENCHMARK_DEFINE_F(BmNanoflann, KnnCt)(benchmark::State& state) {
6767
int max_leaf_size = state.range(0);
6868
int knn_count = state.range(1);
69-
NanoAdaptorX adaptor(points_);
69+
NanoAdaptorX adaptor(points_tree_);
7070
NanoKdTreeCt<NanoAdaptorX> tree(
7171
PointX::Dim,
7272
adaptor,
@@ -77,7 +77,7 @@ BENCHMARK_DEFINE_F(BmNanoflann, KnnCt)(benchmark::State& state) {
7777
std::vector<Index> indices(knn_count);
7878
std::vector<Scalar> distances(knn_count);
7979
std::size_t sum = 0;
80-
for (auto const& p : points_) {
80+
for (auto const& p : points_test_) {
8181
benchmark::DoNotOptimize(
8282
sum +=
8383
tree.knnSearch(p.data, knn_count, indices.data(), distances.data()));
@@ -120,9 +120,9 @@ BENCHMARK_REGISTER_F(BmNanoflann, KnnCt)
120120

121121
BENCHMARK_DEFINE_F(BmNanoflann, RadiusCt)(benchmark::State& state) {
122122
int max_leaf_size = state.range(0);
123-
double radius = static_cast<double>(state.range(1)) / 10.0;
124-
double squared = radius * radius;
125-
NanoAdaptorX adaptor(points_);
123+
Scalar radius = static_cast<Scalar>(state.range(1)) / 10.0;
124+
Scalar squared = radius * radius;
125+
NanoAdaptorX adaptor(points_tree_);
126126
NanoKdTreeCt<NanoAdaptorX> tree(
127127
PointX::Dim,
128128
adaptor,
@@ -132,7 +132,7 @@ BENCHMARK_DEFINE_F(BmNanoflann, RadiusCt)(benchmark::State& state) {
132132
for (auto _ : state) {
133133
std::vector<std::pair<Index, Scalar>> results;
134134
std::size_t sum = 0;
135-
for (auto const& p : points_) {
135+
for (auto const& p : points_test_) {
136136
benchmark::DoNotOptimize(
137137
sum += tree.radiusSearch(
138138
p.data, squared, results, nanoflann::SearchParams{0, 0, false}));

examples/benchmark/bm_opencv_flann.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class BmOpenCvFlann : public pico_tree::Benchmark {
1919

2020
BENCHMARK_DEFINE_F(BmOpenCvFlann, BuildRt)(benchmark::State& state) {
2121
int max_leaf_size = state.range(0);
22-
cvflann::Matrix<Scalar> matrix(points_.data()->data, points_.size(), 3);
22+
cvflann::Matrix<Scalar> matrix(
23+
points_tree_.data()->data, points_tree_.size(), 3);
2324
// Reorder will change the order of the input to fit the generated indices,
2425
// but it will replace (delete) the original input.
2526
cvflann::KDTreeSingleIndexParams pindex(max_leaf_size, false);
@@ -43,7 +44,8 @@ BENCHMARK_DEFINE_F(BmOpenCvFlann, KnnRt)(benchmark::State& state) {
4344
int max_leaf_size = state.range(0);
4445
int knn_count = state.range(1);
4546

46-
cvflann::Matrix<Scalar> matrix(points_.data()->data, points_.size(), 3);
47+
cvflann::Matrix<Scalar> matrix(
48+
points_tree_.data()->data, points_tree_.size(), 3);
4749
// Reorder will change the order of the input to fit the generated indices,
4850
// but it will replace (and delete) the original input. Note that the reorder
4951
// option does not appear to have effect on the performance of the queries.
@@ -68,7 +70,7 @@ BENCHMARK_DEFINE_F(BmOpenCvFlann, KnnRt)(benchmark::State& state) {
6870
cvflann::Matrix<Index> mat_indices(indices.data(), 1, knn_count);
6971
cvflann::Matrix<Scalar> mat_distances(distances.data(), 1, knn_count);
7072

71-
for (auto& p : points_) {
73+
for (auto& p : points_test_) {
7274
cvflann::Matrix<Scalar> query(p.data, 1, 3);
7375
tree.knnSearch(query, mat_indices, mat_distances, knn_count, psearch);
7476
}

examples/benchmark/bm_pico_cover_tree.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ BENCHMARK_DEFINE_F(BmPicoCoverTree, BuildCt)(benchmark::State& state) {
2424
Scalar base = static_cast<Scalar>(state.range(0)) / Scalar(10.0);
2525

2626
for (auto _ : state) {
27-
PicoCoverTree<PointX> tree(points_, base);
27+
PicoCoverTree<PointX> tree(points_tree_, base);
2828
}
2929
}
3030

@@ -41,19 +41,19 @@ BENCHMARK_DEFINE_F(BmPicoCoverTree, KnnCt)(benchmark::State& state) {
4141
Scalar base = static_cast<Scalar>(state.range(0)) / Scalar(10.0);
4242
int knn_count = state.range(1);
4343

44-
PicoCoverTree<PointX> tree(points_, base);
44+
PicoCoverTree<PointX> tree(points_tree_, base);
4545

4646
for (auto _ : state) {
4747
std::vector<pico_tree::Neighbor<Index, Scalar>> results;
4848
std::size_t sum = 0;
4949
std::size_t group = 4000;
5050
std::size_t pi = 0;
51-
while (pi < points_.size()) {
52-
std::size_t group_end = std::min(pi + group, points_.size());
51+
while (pi < points_test_.size()) {
52+
std::size_t group_end = std::min(pi + group, points_test_.size());
5353
std::flush(std::cout);
5454
ScopedTimer timer("query_group");
5555
for (; pi < group_end; ++pi) {
56-
auto const& p = points_[pi];
56+
auto const& p = points_test_[pi];
5757
tree.SearchKnn(p, knn_count, &results);
5858
benchmark::DoNotOptimize(sum += results.size());
5959
}

examples/benchmark/bm_pico_kd_tree.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,31 @@ BENCHMARK_DEFINE_F(BmPicoKdTree, BuildCtSldMid)(benchmark::State& state) {
4343
int max_leaf_size = state.range(0);
4444

4545
for (auto _ : state) {
46-
PicoKdTreeCtSldMid<PointX> tree(points_, max_leaf_size);
46+
PicoKdTreeCtSldMid<PointX> tree(points_tree_, max_leaf_size);
4747
}
4848
}
4949

5050
BENCHMARK_DEFINE_F(BmPicoKdTree, BuildCtLngMed)(benchmark::State& state) {
5151
int max_leaf_size = state.range(0);
5252

5353
for (auto _ : state) {
54-
PicoKdTreeCtLngMed<PointX> tree(points_, max_leaf_size);
54+
PicoKdTreeCtLngMed<PointX> tree(points_tree_, max_leaf_size);
5555
}
5656
}
5757

5858
BENCHMARK_DEFINE_F(BmPicoKdTree, BuildRtSldMid)(benchmark::State& state) {
5959
int max_leaf_size = state.range(0);
6060

6161
for (auto _ : state) {
62-
PicoKdTreeRtSldMid<PointX> tree(points_, max_leaf_size);
62+
PicoKdTreeRtSldMid<PointX> tree(points_tree_, max_leaf_size);
6363
}
6464
}
6565

6666
BENCHMARK_DEFINE_F(BmPicoKdTree, BuildRtLngMed)(benchmark::State& state) {
6767
int max_leaf_size = state.range(0);
6868

6969
for (auto _ : state) {
70-
PicoKdTreeRtLngMed<PointX> tree(points_, max_leaf_size);
70+
PicoKdTreeRtLngMed<PointX> tree(points_tree_, max_leaf_size);
7171
}
7272
}
7373

@@ -98,12 +98,12 @@ BENCHMARK_DEFINE_F(BmPicoKdTree, KnnCtSldMid)(benchmark::State& state) {
9898
int max_leaf_size = state.range(0);
9999
int knn_count = state.range(1);
100100

101-
PicoKdTreeCtSldMid<PointX> tree(points_, max_leaf_size);
101+
PicoKdTreeCtSldMid<PointX> tree(points_tree_, max_leaf_size);
102102

103103
for (auto _ : state) {
104104
std::vector<pico_tree::Neighbor<Index, Scalar>> results;
105105
std::size_t sum = 0;
106-
for (auto const& p : points_) {
106+
for (auto const& p : points_test_) {
107107
tree.SearchKnn(p, knn_count, &results);
108108
benchmark::DoNotOptimize(sum += results.size());
109109
}
@@ -114,12 +114,12 @@ BENCHMARK_DEFINE_F(BmPicoKdTree, KnnCtLngMed)(benchmark::State& state) {
114114
int max_leaf_size = state.range(0);
115115
int knn_count = state.range(1);
116116

117-
PicoKdTreeCtLngMed<PointX> tree(points_, max_leaf_size);
117+
PicoKdTreeCtLngMed<PointX> tree(points_tree_, max_leaf_size);
118118

119119
for (auto _ : state) {
120120
std::vector<pico_tree::Neighbor<Index, Scalar>> results;
121121
std::size_t sum = 0;
122-
for (auto const& p : points_) {
122+
for (auto const& p : points_test_) {
123123
tree.SearchKnn(p, knn_count, &results);
124124
benchmark::DoNotOptimize(sum += results.size());
125125
}
@@ -129,11 +129,11 @@ BENCHMARK_DEFINE_F(BmPicoKdTree, KnnCtLngMed)(benchmark::State& state) {
129129
BENCHMARK_DEFINE_F(BmPicoKdTree, NnCtSldMid)(benchmark::State& state) {
130130
int max_leaf_size = state.range(0);
131131

132-
PicoKdTreeCtSldMid<PointX> tree(points_, max_leaf_size);
132+
PicoKdTreeCtSldMid<PointX> tree(points_tree_, max_leaf_size);
133133

134134
for (auto _ : state) {
135135
pico_tree::Neighbor<Index, Scalar> result;
136-
for (auto const& p : points_) {
136+
for (auto const& p : points_test_) {
137137
tree.SearchNn(p, &result);
138138
}
139139
}
@@ -142,11 +142,11 @@ BENCHMARK_DEFINE_F(BmPicoKdTree, NnCtSldMid)(benchmark::State& state) {
142142
BENCHMARK_DEFINE_F(BmPicoKdTree, NnCtLngMed)(benchmark::State& state) {
143143
int max_leaf_size = state.range(0);
144144

145-
PicoKdTreeCtLngMed<PointX> tree(points_, max_leaf_size);
145+
PicoKdTreeCtLngMed<PointX> tree(points_tree_, max_leaf_size);
146146

147147
for (auto _ : state) {
148148
pico_tree::Neighbor<Index, Scalar> result;
149-
for (auto const& p : points_) {
149+
for (auto const& p : points_test_) {
150150
tree.SearchNn(p, &result);
151151
}
152152
}
@@ -217,15 +217,15 @@ BENCHMARK_REGISTER_F(BmPicoKdTree, NnCtLngMed)
217217

218218
BENCHMARK_DEFINE_F(BmPicoKdTree, RadiusCtSldMid)(benchmark::State& state) {
219219
int max_leaf_size = state.range(0);
220-
double radius = static_cast<double>(state.range(1)) / 10.0;
221-
double squared = radius * radius;
220+
Scalar radius = static_cast<Scalar>(state.range(1)) / 10.0;
221+
Scalar squared = radius * radius;
222222

223-
PicoKdTreeCtSldMid<PointX> tree(points_, max_leaf_size);
223+
PicoKdTreeCtSldMid<PointX> tree(points_tree_, max_leaf_size);
224224

225225
for (auto _ : state) {
226226
std::vector<pico_tree::Neighbor<Index, Scalar>> results;
227227
std::size_t sum = 0;
228-
for (auto const& p : points_) {
228+
for (auto const& p : points_test_) {
229229
tree.SearchRadius(p, squared, &results);
230230
benchmark::DoNotOptimize(sum += results.size());
231231
}

0 commit comments

Comments
 (0)