Advertisement
obernardovieira

(Speed Test) Distance between 65535 points! boost vs c++std

Apr 12th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3. #include <boost/geometry.hpp>
  4.  
  5. #define SIZE_DOUBLE 65535
  6.  
  7. int main() {
  8.     auto myarray = new double[SIZE_DOUBLE][3]();
  9.     double startd = 1.0;
  10.     for(int t=0; t!=SIZE_DOUBLE; t++) {
  11.         myarray[t][0] = startd;
  12.         myarray[t][1] = 1.0;
  13.         myarray[t][2] = 1.0;
  14.         startd += 1.0;
  15.     }
  16.  
  17.     std::cout << "mine ...\n\n\n" << std::endl;
  18.  
  19.     std::chrono::time_point<std::chrono::system_clock> start_time = std::chrono::system_clock::now();
  20.     double cpoint[3], *mpoint;
  21.     cpoint[0] = 6.0; cpoint[1] = 2.0; cpoint[2] = 1.0;
  22.     double min_d = 65535;
  23.     for(int t=0; t!=SIZE_DOUBLE; t++) {
  24.         double d = std::pow((myarray[t][0]-cpoint[0]), 2) + std::pow((myarray[t][1]-cpoint[1]), 2)
  25.         + std::pow((myarray[t][2]-cpoint[2]), 2) ;
  26.         if (d < min_d) {
  27.             min_d = d;
  28.             mpoint = myarray[t];
  29.         }
  30.     }
  31.     std::chrono::time_point<std::chrono::system_clock> end_time = std::chrono::system_clock::now();
  32.     std::cout  << "Closest: (" << mpoint[0] << "," << mpoint[1] << "," << mpoint[2] << ")" << std::endl
  33.         << "At: " << std::sqrt( std::pow((mpoint[0]-cpoint[0]), 2) +
  34.             std::pow((mpoint[1]-cpoint[1]), 2) + std::pow((mpoint[2]-cpoint[2]), 2) ) << std::endl
  35.         << "In: " << std::chrono::duration_cast<std::chrono::milliseconds>
  36.             (end_time - start_time).count() << " milliseconds" << std::endl;
  37.  
  38.     std::cout << "\n\n\nboost ...\n\n\n" << std::endl;
  39.  
  40.     std::chrono::time_point<std::chrono::system_clock> start_time2 = std::chrono::system_clock::now();
  41.     typedef boost::geometry::model::point<double, 3, boost::geometry::cs::cartesian> mypoint;
  42.     mypoint p, pv, min_p;
  43.     boost::geometry::assign_values(p, 6.0, 2.0, 1.0);
  44.     double min_d2 = 65535;
  45.     for(int t=0; t!=SIZE_DOUBLE; t++) {
  46.         boost::geometry::assign_values(pv, myarray[t][0], myarray[t][1], myarray[t][2]);
  47.         double d = boost::geometry::comparable_distance(p, pv);
  48.         if (d < min_d2) {
  49.             min_d2 = d;
  50.             min_p = pv;
  51.         }
  52.     }
  53.     std::chrono::time_point<std::chrono::system_clock> end_time2 = std::chrono::system_clock::now();
  54.     std::cout
  55.         << "Closest: " << boost::geometry::dsv(min_p) << std::endl
  56.         << "At: " << boost::geometry::distance(p, min_p) << std::endl
  57.         << "In: " << std::chrono::duration_cast<std::chrono::milliseconds>
  58.             (end_time2 - start_time2).count() << " milliseconds" << std::endl;
  59.  
  60.  
  61.  
  62.     std::cin.get();
  63.     return 1;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement