diff --git a/Hash_map/benchmark/Hash_map/polyhedron.cpp b/Hash_map/benchmark/Hash_map/polyhedron.cpp index fbc501c2a86..1d45c71149c 100644 --- a/Hash_map/benchmark/Hash_map/polyhedron.cpp +++ b/Hash_map/benchmark/Hash_map/polyhedron.cpp @@ -2,12 +2,10 @@ #include #include #include +#include #include #include -#include -#include -#include #include #include @@ -18,18 +16,104 @@ #include #include -typedef CGAL::Simple_cartesian Kernel; -typedef Kernel::Point_3 Point_3; +typedef CGAL::Simple_cartesian Kernel; +struct Point_3 : Kernel::Point_3 { + using Kernel::Point_3::operator=; + Point_3() : Kernel::Point_3(0,0,0) {} + Point_3(int i) : Kernel::Point_3(i,0,0) {} +}; typedef Kernel::Vector_3 Vector_3; typedef CGAL::Polyhedron_3 Mesh; +typedef boost::property_map::type VPM; typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef std::vector Vertex_list; typedef CGAL::Timer Timer; +template +auto reserve(Map& sm, typename Map::size_type ii) -> decltype(sm.reserve(ii), void()){ + sm.reserve(ii); +} +template +Point_3 lookup(Map& sm,vertex_descriptor vh){ + auto search = sm.find(vh); + if(search != sm.end()) + return search->second; + return Point_3(); +} + +template +Point_3 lookup(CGAL::Unique_hash_map& sm,vertex_descriptor vh){ + const CGAL::Unique_hash_map& const_sm = sm; + return const_sm[vh]; +} + +template +int fct(int ii, int jj, const Vertex_list& V, const Vertex_list& V2, const VPM& vpm, const std::string& s) +{ + int x = 0; + Timer construct, query, lookups; + construct.start(); + for(int j=0; j SM; @@ -37,106 +121,28 @@ void fct(int ii, int jj) typedef boost::unordered_map BUM; typedef CGAL::Unique_hash_map UHM; + Mesh mesh1; + VPM vpm1 = get(CGAL::vertex_point,mesh1); + Vertex_list V1; + random_mesh(ii,jj,mesh1,vpm1,V1); - Mesh mesh; - typedef boost::property_map::type VPM; - VPM vpm = get(CGAL::vertex_point,mesh); + Mesh mesh2; + VPM vpm2 = get(CGAL::vertex_point,mesh2); + Vertex_list V2; + random_mesh(ii,jj,mesh2,vpm2,V2); - Vector_3 v(0,0,0); - - for(int i =0; i < ii; i++){ - vertex_descriptor vd = add_vertex(mesh); - put(vpm,vd, Point_3(i,0,0)); - } - - std::vector V; - for(vertex_descriptor vd : vertices(mesh)){ - V.push_back(vd); - } - random_shuffle(V.begin(), V.end()); - - - Timer tsmc, tsumc, tbumc, tuhmc; - Timer tsmq, tsumq, tbumq, tuhmq; - - for(int j=0; j (ii,jj, V1,V2, vpm1, "std::map\t\t|\t\t| " ); + temp = fct(ii,jj,V1,V2, vpm1, "std::unordered_map\t|\t\t| " ); + if(temp != res){ std::cout << temp << " != " << res << std::endl;} + temp = fct(ii,jj, V1,V2, vpm1, "boost::unordered_map\t|\t\t| " ); + if(temp != res){ std::cout << temp << " != " << res << std::endl;} + temp = fct(ii,jj,V1,V2, vpm1, "CGAL::Unique_hash_map\t| master\t| " ); + if(temp != res){ std::cout << temp << " != " << res << std::endl;} } int main(int , char* argv[]) @@ -148,5 +154,6 @@ int main(int , char* argv[]) fct(500, 20000); fct(250, 40000); fct(100, 100000); + fct(10, 1000000); return 0; }