DGtal  1.5.beta
benchmarkHyperRectDomain-google.cpp
1 
32 #include <iostream>
33 #include <numeric>
34 #include <chrono>
35 
36 #include <benchmark/benchmark.h>
37 
38 #include "DGtal/base/Common.h"
39 #include "DGtal/kernel/SpaceND.h"
40 #include "DGtal/kernel/PointVector.h"
41 #include "DGtal/kernel/domains/HyperRectDomain.h"
42 
43 using namespace DGtal;
44 using namespace std;
45 
46 // Context for each benchmark
47 struct BenchDomain
48  : public benchmark::Fixture
49 {
50  static constexpr std::size_t dim = 3;
51  static constexpr signed long long int size = 200;
52 
53  using Space = DGtal::SpaceND<dim>;
54  using Point = Space::Point;
56 
57  BenchDomain()
58  : a(Point::diagonal(0))
59  , b(Point::diagonal(size))
60  , domain(Domain(a, b))
61  , dimensions(Point::dimension)
62  {
63  std::iota(dimensions.begin(), dimensions.end(), Dimension(0));
64  }
65 
66  Point a, b;
67  Domain domain;
68  std::vector<Point::Dimension> dimensions;
69 };
70 
71 
72 BENCHMARK_DEFINE_F(BenchDomain, DomainTraversal)(benchmark::State& state)
73 {
74  for (auto _ : state)
75  {
76  Point check;
77  for (auto const& pt : domain)
78  check += pt;
79  benchmark::DoNotOptimize(check);
80  }
81 
82  state.SetItemsProcessed(domain.size() * state.iterations());
83 }
84 
85 BENCHMARK_DEFINE_F(BenchDomain, DomainReverseTraversal)(benchmark::State& state)
86 {
87  for (auto _ : state)
88  {
89  Point check;
90  for (auto it = domain.rbegin(), it_end = domain.rend(); it != it_end; ++it)
91  check += *it;
92  benchmark::DoNotOptimize(check);
93  }
94 
95  state.SetItemsProcessed(domain.size() * state.iterations());
96 }
97 
98 BENCHMARK_DEFINE_F(BenchDomain, DomainTraversalSubRange)(benchmark::State& state)
99 {
100  for (auto _ : state)
101  {
102  Point check;
103  for (auto const& pt : domain.subRange(dimensions))
104  check += pt;
105  benchmark::DoNotOptimize(check);
106  }
107 
108  state.SetItemsProcessed(domain.size() * state.iterations());
109 }
110 
111 BENCHMARK_DEFINE_F(BenchDomain, DomainReverseTraversalSubRange)(benchmark::State& state)
112 {
113  for (auto _ : state)
114  {
115  Point check;
116  const auto range = domain.subRange(dimensions);
117  for (auto it = range.rbegin(), it_end = range.rend(); it != it_end; ++it)
118  check += *it;
119  benchmark::DoNotOptimize(check);
120  }
121 
122  state.SetItemsProcessed(domain.size() * state.iterations());
123 }
124 
125 BENCHMARK_REGISTER_F(BenchDomain, DomainTraversal)->Unit(benchmark::kMillisecond);
126 BENCHMARK_REGISTER_F(BenchDomain, DomainReverseTraversal)->Unit(benchmark::kMillisecond);
127 BENCHMARK_REGISTER_F(BenchDomain, DomainTraversalSubRange)->Unit(benchmark::kMillisecond);
128 BENCHMARK_REGISTER_F(BenchDomain, DomainReverseTraversalSubRange)->Unit(benchmark::kMillisecond);
129 
130 int main(int argc, char* argv[])
131 {
132  benchmark::Initialize(&argc, argv);
133  benchmark::RunSpecifiedBenchmarks();
134 
135  return 0;
136 }
137 
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
int main(int argc, char **argv)
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
unsigned int dim(const Vector &z)