DGtal 1.4.0
Loading...
Searching...
No Matches
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
50using namespace std;
51using namespace DGtal;
52
53
57
61
62template<typename Q>
63static 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}
77BENCHMARK_TEMPLATE(BM_Constructor, FromVector3)->Range(1<<3 , 1 << 8);
78BENCHMARK_TEMPLATE(BM_Constructor, FromSet3)->Range(1<<3 , 1 << 8);
80
81
82template<typename Q>
83static 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
106template<typename Q>
107static 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}
124BENCHMARK_TEMPLATE(BM_iterate, FromVector)->Range(1<<3 , 1 << 10);;
125BENCHMARK_TEMPLATE(BM_iterate, FromSet)->Range(1<<3 , 1 << 10);;
127BENCHMARK_TEMPLATE(BM_iterate, FromVector3)->Range(1<<3 , 1 << 10);;
128BENCHMARK_TEMPLATE(BM_iterate, FromSet3)->Range(1<<3 , 1 << 10);;
129BENCHMARK_TEMPLATE(BM_iterate, FromUnordered3)->Range(1<<3 , 1 << 10);;
130
131
133// Standard services - public :
134
135int 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)
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.
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
int main()
Definition testBits.cpp:56