From 1a9f620031c975fc2400978837b302d9ec28c06c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 1 Feb 2022 07:21:06 +0000 Subject: [PATCH 1/6] Restructure the code so that the timer is not permanently switched on and off --- Hash_map/benchmark/Hash_map/polyhedron.cpp | 138 ++++++++------------- 1 file changed, 51 insertions(+), 87 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/polyhedron.cpp b/Hash_map/benchmark/Hash_map/polyhedron.cpp index fbc501c2a86..7dc24ed89c9 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,7 +16,7 @@ #include #include -typedef CGAL::Simple_cartesian Kernel; +typedef CGAL::Simple_cartesian Kernel; typedef Kernel::Point_3 Point_3; typedef Kernel::Vector_3 Vector_3; @@ -29,6 +27,41 @@ typedef boost::graph_traits::vertex_descriptor vertex_descriptor; typedef CGAL::Timer Timer; +template +double fct(int ii, int jj, const std::vector& V, const VPM& vpm, const std::string& s) +{ + int x = 0; + Timer construct, query; + construct.start(); + for(int j=0; j ::type VPM; VPM vpm = get(CGAL::vertex_point,mesh); - - 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)); @@ -54,89 +84,22 @@ void fct(int ii, int jj) for(vertex_descriptor vd : vertices(mesh)){ V.push_back(vd); } - random_shuffle(V.begin(), V.end()); + + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(V.begin(), V.end(), g); - Timer tsmc, tsumc, tbumc, tuhmc; - Timer tsmq, tsumq, tbumq, tuhmq; - - for(int j=0; j (ii,jj, V, vpm, "std::map " ); + temp = fct(ii,jj,V, vpm, "std::unordered_map " ); + if(temp != res){ std::cout << temp << " != " << res << std::endl;} + temp = fct(ii,jj, V, vpm, "boost::unordered_map " ); + if(temp != res){ std::cout << temp << " != " << res << std::endl;} + temp = fct(ii,jj, V, vpm, "CGAL::Unique_hash_map" ); + if(temp != res){ std::cout << temp << " != " << res << std::endl;} } int main(int , char* argv[]) @@ -148,5 +111,6 @@ int main(int , char* argv[]) fct(500, 20000); fct(250, 40000); fct(100, 100000); + fct(10, 1000000); return 0; } From 74290b7a0e1656e97647e1397cf93f8c0e41831d Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Wed, 2 Feb 2022 20:18:45 +0000 Subject: [PATCH 2/6] Use reserve only when available --- Hash_map/benchmark/Hash_map/polyhedron.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Hash_map/benchmark/Hash_map/polyhedron.cpp b/Hash_map/benchmark/Hash_map/polyhedron.cpp index 7dc24ed89c9..89c08f31108 100644 --- a/Hash_map/benchmark/Hash_map/polyhedron.cpp +++ b/Hash_map/benchmark/Hash_map/polyhedron.cpp @@ -26,6 +26,10 @@ typedef boost::graph_traits::vertex_descriptor vertex_descriptor; typedef CGAL::Timer Timer; +template +auto reserve(Map& sm, typename Map::size_type ii) -> decltype(sm.reserve(ii), void()){ + sm.reserve(ii); +} template double fct(int ii, int jj, const std::vector& V, const VPM& vpm, const std::string& s) @@ -35,6 +39,7 @@ double fct(int ii, int jj, const std::vector& V, const VPM& v construct.start(); for(int j=0; j Date: Thu, 3 Feb 2022 17:55:44 +0000 Subject: [PATCH 3/6] Include benchmark for lookups of non-exsistant vertices --- Hash_map/benchmark/Hash_map/polyhedron.cpp | 91 +++++++++++++++------- 1 file changed, 65 insertions(+), 26 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/polyhedron.cpp b/Hash_map/benchmark/Hash_map/polyhedron.cpp index 89c08f31108..ccaf89d42fb 100644 --- a/Hash_map/benchmark/Hash_map/polyhedron.cpp +++ b/Hash_map/benchmark/Hash_map/polyhedron.cpp @@ -17,12 +17,18 @@ #include typedef CGAL::Simple_cartesian Kernel; -typedef Kernel::Point_3 Point_3; +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; @@ -31,11 +37,26 @@ auto reserve(Map& sm, typename Map::size_type ii) -> decltype(sm.reserve(ii), vo sm.reserve(ii); } -template -double fct(int ii, int jj, const std::vector& V, const VPM& vpm, const std::string& s) + +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 +double 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; + Timer construct, query, lookups; construct.start(); for(int j=0; j & V, const VPM& v } query.stop(); + int y=0; + lookups.start(); + for(int j=0; j 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); - - 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); - } - - std::random_device rd; - std::mt19937 g(rd()); - std::shuffle(V.begin(), V.end(), g); + Mesh mesh2; + VPM vpm2 = get(CGAL::vertex_point,mesh2); + Vertex_list V2; + random_mesh(ii,jj,mesh2,vpm2,V2); std::cerr << std::endl << ii << " items and queries (repeated " << jj << " times)" << std::endl; int temp; - int res = fct(ii,jj, V, vpm, "std::map " ); - temp = fct(ii,jj,V, vpm, "std::unordered_map " ); + int res = fct(ii,jj, V1,V2, vpm1, "std::map " ); + temp = fct(ii,jj,V1,V2, vpm1, "std::unordered_map " ); if(temp != res){ std::cout << temp << " != " << res << std::endl;} - temp = fct(ii,jj, V, vpm, "boost::unordered_map " ); + temp = fct(ii,jj, V1,V2, vpm1, "boost::unordered_map " ); if(temp != res){ std::cout << temp << " != " << res << std::endl;} - temp = fct(ii,jj, V, vpm, "CGAL::Unique_hash_map" ); + temp = fct(ii,jj,V1,V2, vpm1, "CGAL::Unique_hash_map" ); if(temp != res){ std::cout << temp << " != " << res << std::endl;} } From 2527f17b17f90f83538b56e09e706958a4176ed5 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Thu, 3 Feb 2022 18:08:41 +0000 Subject: [PATCH 4/6] Replace tabs with spaces --- Hash_map/benchmark/Hash_map/polyhedron.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/polyhedron.cpp b/Hash_map/benchmark/Hash_map/polyhedron.cpp index ccaf89d42fb..63cdc271686 100644 --- a/Hash_map/benchmark/Hash_map/polyhedron.cpp +++ b/Hash_map/benchmark/Hash_map/polyhedron.cpp @@ -18,9 +18,9 @@ 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) {} + 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; From eb7d36e8b39e4c3d340124d3c8b7b5bf3029bd00 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Fri, 4 Feb 2022 17:56:32 +0000 Subject: [PATCH 5/6] Use tabulated output to easily compare results --- Hash_map/benchmark/Hash_map/polyhedron.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Hash_map/benchmark/Hash_map/polyhedron.cpp b/Hash_map/benchmark/Hash_map/polyhedron.cpp index 63cdc271686..41348b5f8ba 100644 --- a/Hash_map/benchmark/Hash_map/polyhedron.cpp +++ b/Hash_map/benchmark/Hash_map/polyhedron.cpp @@ -91,9 +91,7 @@ double fct(int ii, int jj, const Vertex_list& V, const Vertex_list& V2, const VP if(y != 0) { std::cout << y << " != 0" << std::endl;} - std::cerr << s << " construction : "<< construct.time() << " sec. "; - std::cerr << " queries : "<< query.time() << " sec."; - std::cerr << " lookup : "<< lookups.time() << " sec." << std::endl; + std::cerr << s << construct.time() << " sec.\t| " << query.time() << " sec.\t| " << lookups.time() << " sec." << std::endl; return x; } @@ -134,15 +132,16 @@ void fct(int ii, int jj) random_mesh(ii,jj,mesh2,vpm2,V2); - std::cerr << std::endl << ii << " items and queries (repeated " << jj << " times)" << std::endl; + std::cerr << std::endl << ii << " items and queries (repeated " << jj << " times)" << std::endl; + std::cerr << "Name\t\t\t| Version\t| Construction\t| Queries\t| Lookups" << std::endl; int temp; - int res = fct(ii,jj, V1,V2, vpm1, "std::map " ); - temp = fct(ii,jj,V1,V2, vpm1, "std::unordered_map " ); + int res = fct(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 " ); + 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" ); + temp = fct(ii,jj,V1,V2, vpm1, "CGAL::Unique_hash_map\t| master\t| " ); if(temp != res){ std::cout << temp << " != " << res << std::endl;} } From 4e79edebc6a300985384d745cdf7ec1069481c63 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Fri, 4 Feb 2022 18:01:12 +0000 Subject: [PATCH 6/6] double should be an int --- Hash_map/benchmark/Hash_map/polyhedron.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hash_map/benchmark/Hash_map/polyhedron.cpp b/Hash_map/benchmark/Hash_map/polyhedron.cpp index 41348b5f8ba..1d45c71149c 100644 --- a/Hash_map/benchmark/Hash_map/polyhedron.cpp +++ b/Hash_map/benchmark/Hash_map/polyhedron.cpp @@ -53,7 +53,7 @@ Point_3 lookup(CGAL::Unique_hash_map& sm,vertex_descriptor vh){ } template -double fct(int ii, int jj, const Vertex_list& V, const Vertex_list& V2, const VPM& vpm, const std::string& s) +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;