コード例 #1
0
void compare_libraries(std::size_t         data_size,
                       const Distribution& distribution) {
    std::cout << "\t" << N << " dimensions, " << data_size
              << " objects:" << std::endl;
    std::vector<Point> data;
    std::vector<Point> targets;
    data.reserve(data_size);
    targets.reserve(data_size);
    for (std::size_t i = 0; i < data_size; ++i) {
        data.push_back(Point(distribution));
        targets.push_back(Point(distribution));
    }
    {
        // Nearest neighbor begin into an idle_point_multiset
        std::cout << "\t\tidle_point_multiset:\t" << std::flush;
        spatial::idle_point_multiset<0, Point> cobaye(N);
        cobaye.insert_rebalance(data.begin(), data.end());
        utils::time_point start = utils::process_timer_now();
        for (typename std::vector<Point>::const_iterator i = targets.begin();
             i != targets.end(); ++i)
            neighbor_begin(cobaye, *i);
        utils::time_point stop = utils::process_timer_now();
        std::cout << (stop - start) << "sec" << std::endl;
    }
    {
        // Nearest neighbor begin into an idle_point_multiset
        std::cout << "\t\tpoint_multiset:\t" << std::flush;
        spatial::point_multiset<0, Point> cobaye(N);
        cobaye.insert(data.begin(), data.end());
        utils::time_point start = utils::process_timer_now();
        for (typename std::vector<Point>::const_iterator i = targets.begin();
             i != targets.end(); ++i)
            neighbor_begin(cobaye, *i);
        utils::time_point stop = utils::process_timer_now();
        std::cout << (stop - start) << "sec" << std::endl;
    }
    {
        // Nearest neighbor into an KDtree
        std::cout << "\t\tKDtree:\t" << std::flush;
        KDTree::KDTree<N, Point> cobaye;
        cobaye.insert(data.begin(), data.end());
        cobaye.optimise();
        utils::time_point start = utils::process_timer_now();
        for (typename std::vector<Point>::const_iterator i = targets.begin();
             i != targets.end(); ++i)
            cobaye.find_nearest(*i);
        utils::time_point stop = utils::process_timer_now();
        std::cout << (stop - start) << "sec" << std::endl;
    }
}
コード例 #2
0
void compare_libraries
(std::size_t data_size, const Distribution& distribution)
{
  std::cout << "\t" << N << " dimensions, " << data_size << " objects:" << std::endl;
  std::vector<Point> data;
  data.reserve(data_size);
  for (size_t i = 0; i < data_size; ++i)
    data.push_back(Point(distribution));
  {
    // Erase into a point_multiset
    std::cout << "\t\tpoint_multiset:\t" << std::flush;
    spatial::point_multiset<N, Point> cobaye;
    cobaye.insert(data.begin(), data.end());
    std::random_shuffle(data.begin(), data.end(), random_integer);
    utils::time_point start = utils::process_timer_now();
    for (typename std::vector<Point>::const_iterator i = data.begin();
         i != data.end(); ++i)
      cobaye.erase(*i);
    utils::time_point stop = utils::process_timer_now();
    std::cout << (stop - start) << "sec" << std::endl;
  }
  {
    // Erase into an idle_point_multiset
    std::cout << "\t\tidle_point_multiset:\t" << std::flush;
    spatial::idle_point_multiset<N, Point> cobaye;
    cobaye.insert_rebalance(data.begin(), data.end());
    std::random_shuffle(data.begin(), data.end(), random_integer);
    utils::time_point start = utils::process_timer_now();
    for (typename std::vector<Point>::const_iterator i = data.begin();
         i != data.end(); ++i)
      cobaye.erase(*i);
    utils::time_point stop = utils::process_timer_now();
    std::cout << (stop - start) << "sec" << std::endl;
  }
  {
    // Insert into a KDtree
    std::cout << "\t\tKDtree:\t" << std::flush;
    KDTree::KDTree<N, Point> cobaye;
    cobaye.insert(data.begin(), data.end());
    cobaye.optimise();
    std::random_shuffle(data.begin(), data.end(), random_integer);
    utils::time_point start = utils::process_timer_now();
    for (typename std::vector<Point>::const_iterator i = data.begin();
         i != data.end(); ++i)
      cobaye.erase(*i);
    utils::time_point stop = utils::process_timer_now();
    std::cout << (stop - start) << "sec" << std::endl;
  }
}