DGtal  1.5.beta
benchmarkSetContainer.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include <benchmark/benchmark.h>
33 #include <unordered_set>
34 
35 #include "DGtal/base/Common.h"
36 #include "DGtal/kernel/domains/CDomainArchetype.h"
37 #include "DGtal/kernel/sets/DigitalSetBySTLVector.h"
38 #include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
39 #include "DGtal/kernel/sets/DigitalSetByAssociativeContainer.h"
40 #include "DGtal/kernel/sets/DigitalSetFromMap.h"
41 
42 #include "DGtal/kernel/PointHashFunctions.h"
43 
44 #include "DGtal/helpers/StdDefs.h"
45 #include <map>
46 #include <string>
47 
49 
50 using namespace std;
51 using namespace DGtal;
52 
53 
57 
61 
62 template<typename Q>
63 static void BM_Constructor(benchmark::State& state)
64 {
65  while (state.KeepRunning())
66  {
67  state.PauseTiming();
68  typename Q::Domain dom(typename Q::Point().diagonal(0),
69  typename Q::Point().diagonal((typename Q::Domain::Space::Integer)state.range(0)));
70  state.ResumeTiming();
71  Q image( dom );
72  }
73 }
75 BENCHMARK_TEMPLATE(BM_Constructor, FromSet)->Range(1<<3 , 1 << 8);
77 BENCHMARK_TEMPLATE(BM_Constructor, FromVector3)->Range(1<<3 , 1 << 8);
78 BENCHMARK_TEMPLATE(BM_Constructor, FromSet3)->Range(1<<3 , 1 << 8);
79 BENCHMARK_TEMPLATE(BM_Constructor, FromUnordered3)->Range(1<<3 , 1 << 8);
80 
81 
82 template<typename Q>
83 static void BM_insert(benchmark::State& state)
84 {
85  Q myset(typename Q::Domain( Q::Point::diagonal(0), Q::Point::diagonal(2048) ));
86  while (state.KeepRunning())
87  {
88  state.PauseTiming();
89  typename Q::Point p;
90  for(unsigned int j=0; j < Q::Point::dimension; j++)
91  p[j] = rand() % 2048;
92  state.ResumeTiming();
93 
94  myset.insert( p );
95  }
96 }
103 
104 
105 
106 template<typename Q>
107 static void BM_iterate(benchmark::State& state)
108 {
109  Q myset(typename Q::Domain( Q::Point::diagonal(0), Q::Point::diagonal(2048) ));
110  for(unsigned int i= 0; i < state.range(0); ++i)
111  {
112  typename Q::Point p;
113  for(unsigned int j=0; j < Q::Point::dimension; j++)
114  p[j] = rand() % 2048;
115  myset.insert( p );
116  }
117  while (state.KeepRunning())
118  {
119  for(typename Q::ConstIterator it= myset.begin(), itend=myset.end(); it != itend;
120  ++it)
121  benchmark::DoNotOptimize(it);
122  }
123 }
124 BENCHMARK_TEMPLATE(BM_iterate, FromVector)->Range(1<<3 , 1 << 10);;
125 BENCHMARK_TEMPLATE(BM_iterate, FromSet)->Range(1<<3 , 1 << 10);;
126 BENCHMARK_TEMPLATE(BM_iterate, FromUnordered)->Range(1<<3 , 1 << 10);;
127 BENCHMARK_TEMPLATE(BM_iterate, FromVector3)->Range(1<<3 , 1 << 10);;
128 BENCHMARK_TEMPLATE(BM_iterate, FromSet3)->Range(1<<3 , 1 << 10);;
129 BENCHMARK_TEMPLATE(BM_iterate, FromUnordered3)->Range(1<<3 , 1 << 10);;
130 
131 
133 // Standard services - public :
134 
135 int main( int argc, char**argv )
136 {
137  benchmark::Initialize(&argc, argv);
138 
139  benchmark::RunSpecifiedBenchmarks();
140  return 0;
141 }
142 // //
DGtal::DigitalSetBySTLVector< Z3i::Domain > FromVector3
static void BM_insert(benchmark::State &state)
int main(int argc, char **argv)
DGtal::DigitalSetBySTLSet< Z2i::Domain > FromSet
static void BM_Constructor(benchmark::State &state)
static void BM_iterate(benchmark::State &state)
DGtal::DigitalSetBySTLSet< Z3i::Domain > FromSet3
DGtal::DigitalSetByAssociativeContainer< Z3i::Domain, std::unordered_set< Z3i::Point > > FromUnordered3
DGtal::DigitalSetBySTLVector< Z2i::Domain > FromVector
BENCHMARK_TEMPLATE(BM_Constructor, FromVector) -> Range(1<< 3, 1<< 8)
DGtal::DigitalSetByAssociativeContainer< Z2i::Domain, std::unordered_set< Z2i::Point > > FromUnordered
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: A container class for storing sets of digital points within some given domain.
Aim: Realizes the concept CDigitalSet by using the STL container std::vector.
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
Image image(domain)
HyperRectDomain< Space > Domain