From 832a40d63010ef94753d6cb722ad702f6fba2f22 Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Wed, 25 Sep 2019 13:11:46 +0200 Subject: [PATCH] add performance test for smart handles --- src/Unittests/unittests_smart_handles.cc | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/Unittests/unittests_smart_handles.cc b/src/Unittests/unittests_smart_handles.cc index dd29ccf5..fc7d4978 100644 --- a/src/Unittests/unittests_smart_handles.cc +++ b/src/Unittests/unittests_smart_handles.cc @@ -321,4 +321,51 @@ TEST_F(OpenMeshSmartHandles, ComplicatedNavigtaion) } +/* Test performance of smart handles + */ +TEST_F(OpenMeshSmartHandles, Performance) +{ + int n_tests = 10000000; + + auto t_before_old = std::chrono::high_resolution_clock::now(); + + std::vector halfedges0; + for (int i = 0; i < n_tests; ++i) + { + for (auto vh : mesh_.vertices()) + { + auto heh = mesh_.prev_halfedge_handle( + mesh_.prev_halfedge_handle( + mesh_.opposite_halfedge_handle( + mesh_.next_halfedge_handle( + mesh_.next_halfedge_handle( + mesh_.halfedge_handle(vh)))))); + if (i == 0) + halfedges0.push_back(heh); + } + } + + auto t_after_old = std::chrono::high_resolution_clock::now(); + + std::vector halfedges1; + for (int i = 0; i < n_tests; ++i) + { + for (auto vh : mesh_.vertices()) + { + auto svh = OpenMesh::make_smart(vh, mesh_); + auto heh = svh.out().next().next().opp().prev().prev(); + if (i == 0) + halfedges1.push_back(heh); + } + } + + auto t_after_new = std::chrono::high_resolution_clock::now(); + + std::cout << "Conventional navigation took " << std::chrono::duration_cast(t_after_old-t_before_old).count() << "ms" << std::endl; + std::cout << "SmartHandle navigation took " << std::chrono::duration_cast(t_after_new-t_after_old ).count() << "ms" << std::endl; + + EXPECT_EQ(halfedges0, halfedges1) << "halfedges do not match"; + +} + }