DGtal  0.9.2
benchmarkSetContainer.cpp
1 
30 #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(state.range_x()));
70  state.ResumeTiming();
71  Q image( dom );
72  }
73 }
74 BENCHMARK_TEMPLATE(BM_Constructor, FromVector)->Range(1<<3 , 1 << 8);
75 BENCHMARK_TEMPLATE(BM_Constructor, FromSet)->Range(1<<3 , 1 << 8);
76 BENCHMARK_TEMPLATE(BM_Constructor, FromUnordered)->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 }
97 BENCHMARK_TEMPLATE(BM_insert, FromVector);
98 BENCHMARK_TEMPLATE(BM_insert, FromSet);
99 BENCHMARK_TEMPLATE(BM_insert, FromUnordered);
100 BENCHMARK_TEMPLATE(BM_insert, FromVector3);
101 BENCHMARK_TEMPLATE(BM_insert, FromSet3);
102 BENCHMARK_TEMPLATE(BM_insert, FromUnordered3);
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_x(); ++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, const char*argv[] )
136 {
137  benchmark::Initialize(&argc, argv);
138 
139  benchmark::RunSpecifiedBenchmarks();
140  return 0;
141 }
142 // //
STL namespace.
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Realizes the concept CDigitalSet by using the STL container std::vector.
Aim: A container class for storing sets of digital points within some given domain.