diff --git a/example/index/benchmark.cpp b/example/index/benchmark.cpp index dd058de2a..dca151cb9 100644 --- a/example/index/benchmark.cpp +++ b/example/index/benchmark.cpp @@ -25,6 +25,8 @@ int main() size_t values_count = 1000000; size_t queries_count = 100000; + size_t nearest_queries_count = 10000; + unsigned neighbours_count = 10; std::vector< std::pair > coords; @@ -143,17 +145,40 @@ int main() { clock_t::time_point start = clock_t::now(); size_t temp = 0; - for (size_t i = 0 ; i < queries_count / 1 ; ++i ) + for (size_t i = 0 ; i < nearest_queries_count ; ++i ) { float x = coords[i].first + 100; float y = coords[i].second + 100; result.clear(); - temp += t.query(bgi::nearest(P(x, y), 5), std::back_inserter(result)); + temp += t.query(bgi::nearest(P(x, y), neighbours_count), std::back_inserter(result)); } dur_t time = clock_t::now() - start; - std::cout << time << " - query(nearest(P, 5)) " << (queries_count / 10) << " found " << temp << '\n'; + std::cout << time << " - query(nearest(P, " << neighbours_count << ")) " << nearest_queries_count << " found " << temp << '\n'; } +#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL + { + clock_t::time_point start = clock_t::now(); + size_t temp = 0; + for (size_t i = 0 ; i < nearest_queries_count ; ++i ) + { + float x = coords[i].first + 100; + float y = coords[i].second + 100; + result.clear(); + if ( i == 3 ) + { + int a = 10; + } + std::copy(t.qbegin(bgi::nearest(P(x, y), neighbours_count)), + t.qend(bgi::nearest(P(x, y), neighbours_count)), + std::back_inserter(result)); + temp += result.size(); + } + dur_t time = clock_t::now() - start; + std::cout << time << " - nearest_iterator(P, " << neighbours_count << ")) " << nearest_queries_count << " found " << temp << '\n'; + } +#endif + { clock_t::time_point start = clock_t::now(); for (size_t i = 0 ; i < values_count / 10 ; ++i ) diff --git a/test/index/rtree/test_rtree.hpp b/test/index/rtree/test_rtree.hpp index 1c6ca587a..109b22e55 100644 --- a/test/index/rtree/test_rtree.hpp +++ b/test/index/rtree/test_rtree.hpp @@ -860,6 +860,28 @@ struct NearestKTransform } }; +template +void compare_nearest_outputs(Rtree const& rtree, std::vector const& output, std::vector const& expected_output, Point const& pt, Distance greatest_distance) +{ + // check output + bool are_sizes_ok = (expected_output.size() == output.size()); + BOOST_CHECK( are_sizes_ok ); + if ( are_sizes_ok ) + { + BOOST_FOREACH(Value const& v, output) + { + // TODO - perform explicit check here? + // should all objects which are closest be checked and should exactly the same be found? + + if ( find(rtree, expected_output.begin(), expected_output.end(), v) == expected_output.end() ) + { + Distance d = bgi::detail::comparable_distance_near(pt, rtree.indexable_get()(v)); + BOOST_CHECK(d == greatest_distance); + } + } + } +} + template void nearest_query_k(Rtree const& rtree, std::vector const& input, Point const& pt, unsigned int k) { @@ -887,9 +909,9 @@ void nearest_query_k(Rtree const& rtree, std::vector const& input, Point // caluclate biggest distance std::sort(test_output.begin(), test_output.end(), NearestKLess()); - D biggest_d = 0; + D greatest_distance = 0; if ( !test_output.empty() ) - biggest_d = test_output.back().first; + greatest_distance = test_output.back().first; // transform test output to vector of values std::vector expected_output(test_output.size(), generate::value_default::apply()); @@ -900,22 +922,7 @@ void nearest_query_k(Rtree const& rtree, std::vector const& input, Point rtree.query(bgi::nearest(pt, k), std::back_inserter(output)); // check output - bool are_sizes_ok = (expected_output.size() == output.size()); - BOOST_CHECK( are_sizes_ok ); - if ( are_sizes_ok ) - { - BOOST_FOREACH(Value const& v, output) - { - // TODO - perform explicit check here? - // should all objects which are closest be checked and should exactly the same be found? - - if ( find(rtree, expected_output.begin(), expected_output.end(), v) == expected_output.end() ) - { - D d = bgi::detail::comparable_distance_near(pt, rtree.indexable_get()(v)); - BOOST_CHECK(d == biggest_d); - } - } - } + compare_nearest_outputs(rtree, output, expected_output, pt, greatest_distance); exactly_the_same_outputs(rtree, output, rtree | bgi::adaptors::queried(bgi::nearest(pt, k))); @@ -924,6 +931,13 @@ void nearest_query_k(Rtree const& rtree, std::vector const& input, Point output2.resize(found_count, generate::value_default::apply()); exactly_the_same_outputs(rtree, output, output2); + +#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL + std::vector output3; + std::copy(rtree.qbegin(bgi::nearest(pt, k)), rtree.qend(bgi::nearest(pt, k)), std::back_inserter(output3)); + + compare_nearest_outputs(rtree, output3, expected_output, pt, greatest_distance); +#endif } // rtree nearest not found