Пример #1
0
void  fct(int ii, int jj)
{
  typedef std::map<Vertex_handle,Point_2> SM;
  typedef std::unordered_map<Vertex_handle,Point_2> SUM;
  typedef boost::unordered_map<Vertex_handle,Point_2> BUM;
  
  Dt dt;
  Vector_2 v(0,0);
  Random_points rp( 250);
  std::vector<Point_2> points;
  for(int i =0; i < ii; i++){
    Point_2 p = *rp++;
    points.push_back(p); 
  }

  dt.insert(points.begin(), points.end());

  std::vector<Vertex_handle> vertices;
  Finite_vertices_iterator b = dt.finite_vertices_begin(), e = dt.finite_vertices_end();
  for(; b!=e; ++b){
    vertices.push_back(b);
  }
  random_shuffle(vertices.begin(), vertices.end());

  Timer tsmc, tsumc, tbumc;
  Timer tsmq, tsumq, tbumq;
  for(int j=0; j <jj; j++){
    
    {
      tsmc.start();
      SM sm;
      for(Vertex_handle vh : vertices){
        sm[vh] = vh->point();
      }
      tsmc.stop();
      
      
      tsmq.start();
      for(Vertex_handle vh : vertices){
        v = v + (sm[vh] - CGAL::ORIGIN);
      }
      tsmq.stop();
    }
    {
      tsumc.start();
      SUM sm;
      for(Vertex_handle vh : vertices){
        sm[vh] = vh->point();
      }
      tsumc.stop();
      
      
      tsumq.start();
      for(Vertex_handle vh : vertices){
        v = v + (sm[vh] - CGAL::ORIGIN);
      }
      tsumq.stop();
    }
    {
      tbumc.start();
      BUM sm;
      for(Vertex_handle vh : vertices){
        sm[vh] = vh->point();
      }
      tbumc.stop();
      
      
      tbumq.start();
      for(Vertex_handle vh : vertices){
        v = v + (sm[vh] - CGAL::ORIGIN);
      }
      tbumq.stop();
    }
  }
  std::cerr << ii << " items and queries (repeated " << jj << " times)" << std::endl;
  std::cerr << "std::map             construction : "<< tsmc.time() << " sec." << std::endl;
  std::cerr << "std::map             queries      : "<< tsmq.time() << " sec." << std::endl;
  
  std::cerr << "std::unordered_map   construction : "<< tsumc.time() << " sec." << std::endl;
  std::cerr << "std::unordered_map   queries      : "<< tsumq.time() << " sec." << std::endl;
  
  std::cerr << "boost::unordered_map construction : "<< tbumc.time() << " sec." << std::endl;
  std::cerr << "boost::unordered_map queries      : "<< tbumq.time() << " sec.\n" << std::endl;
}