DGtal  1.5.beta
benchmarkHyperRectDomain-catch.cpp
1 
32 #include <iostream>
33 #include <numeric>
34 #include <chrono>
35 
36 #include "DGtal/base/Common.h"
37 #include "DGtal/kernel/SpaceND.h"
38 #include "DGtal/kernel/PointVector.h"
39 #include "DGtal/kernel/domains/HyperRectDomain.h"
40 
41 #include "DGtalCatch.h"
42 
43 using namespace DGtal;
44 using namespace std;
45 
46 // Context for each benchmark
47 struct BenchDomain
48 {
49  static constexpr std::size_t dim = 3;
50  static constexpr signed long long int size = 200;
51 
52  using Space = DGtal::SpaceND<dim>;
53  using Point = Space::Point;
55 
56  BenchDomain()
57  : a(Point::diagonal(0))
58  , b(Point::diagonal(size))
59  , domain(Domain(a, b))
60  , dimensions(Point::dimension)
61  {
62  std::iota(dimensions.begin(), dimensions.end(), Dimension(0));
63  }
64 
65  Point a, b;
66  Domain domain;
67  std::vector<Point::Dimension> dimensions;
68 };
69 
70 
71 TEST_CASE_METHOD(BenchDomain, "Benchmarking HyperRectDomain iterators using Catch2", "[catch]")
72 {
73  BENCHMARK("Domain traversal")
74  {
75  Point check;
76 
77  for (auto const& pt : domain)
78  check += pt;
79 
80  return check;
81  };
82 
83  BENCHMARK("Domain reverse traversal")
84  {
85  Point check;
86 
87  for (auto it = domain.rbegin(), it_end = domain.rend(); it != it_end; ++it)
88  check += *it;
89 
90  return check;
91  };
92 
93  BENCHMARK("Domain traversal using subRange")
94  {
95  Point check;
96 
97  for (auto const& pt : domain.subRange(dimensions))
98  check += pt;
99 
100  return check;
101  };
102 
103  BENCHMARK("Domain reverse traversal using subRange")
104  {
105  Point check;
106  const auto range = domain.subRange(dimensions);
107 
108  for (auto it = range.rbegin(), it_end = range.rend(); it != it_end; ++it)
109  check += *it;
110 
111  return check;
112  };
113 }
114 
ConstReverseIterator rbegin() const
ConstSubRange subRange(const std::vector< Dimension > &permutation) const
ConstReverseIterator rend() const
DGtal::LinearOperator< Calculus, dim, duality, dim, duality > diagonal(const DGtal::KForm< Calculus, dim, duality > &kform)
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Definition: Common.h:136
BENCHMARK(BM_StringCreation)
MyPointD Point
Definition: testClone2.cpp:383
TEST_CASE_METHOD(Fixture_object_diamond_with_hole, "Basic Graph functions", "[interface]")
Domain domain
unsigned int dim(const Vector &z)