32 #include "DGtal/base/Common.h"
34 #include "DGtal/base/Common.h"
35 #include "DGtal/kernel/SpaceND.h"
36 #include "DGtal/kernel/domains/HyperRectDomain.h"
37 #include "DGtal/images/ImageSelector.h"
42 using namespace DGtal;
45 template<
typename Image>
46 double builtinIteratorScan(
const Image &aImage)
55 cpt += (
long int)(*it);
62 template<
typename Image,
typename Domain>
63 double domainIteratorScan(
const Image &aImage,
const Domain &aDomain)
69 for (
typename Domain::ConstIterator it = aDomain.begin(),
70 itend = aDomain.end(); it != itend; ++it)
71 cpt += (
long int) aImage( (*it) );
78 template<
typename Po
int,
typename Image,
typename Domain>
79 bool testSuite(
unsigned int dim,
unsigned int n)
81 double alloc, builtinconstiter, domainiter;
83 Point a = Point::zero, b;
84 for (
unsigned int i = 0; i < dim; i++)
94 Image image( aDomain);
97 builtinconstiter = builtinIteratorScan(image);
98 domainiter = domainIteratorScan<Image, Domain>(image, aDomain);
101 <<
" n=" << n <<
" Alloc=" << alloc
102 <<
" Built-in Iter=" << builtinconstiter
103 <<
" DomainIter=" << domainiter
106 std::cout << dim <<
" " << n <<
" " << alloc <<
" " << builtinconstiter
107 <<
" " << domainiter << std::endl;
112 catch (bad_alloc& ba)
114 trace.
error() <<
"bad_alloc caught: " << ba.what() << endl;
116 <<
" n=" << n <<
" Alloc= XX"
117 <<
" Constiter= XX" << endl;
118 std::cout << dim <<
" " << n <<
" " << std::endl;
131 bool testImageContainerBenchmark()
133 unsigned int dim = 2;
135 std::cout <<
"#dim n alloc built-in-Iter domain-Iter" << std::endl;
137 for (
unsigned int n = 100; n < 2000 ; n = n + 100)
141 typedef Space::Point
Point;
148 if (!testSuite<Point, Image, Domain>(dim, n))
160 for (
unsigned int n = 100; n < 2048 ; n = n + 100)
164 typedef Space::Point Point;
169 if (!testSuite<Point, Image, Domain>(dim, n))
180 for (
unsigned int n = 50; n < 200 ; n = n + 20)
184 typedef Space::Point Point;
189 if (!testSuite<Point, Image, Domain>(dim, n))
200 for (
unsigned int n = 50; n < 100 ; n = n + 10)
204 typedef Space::Point Point;
209 if (!testSuite<Point, Image, Domain>(dim, n))
225 int main(
int argc,
char** argv )
229 for (
int i = 0; i < argc; ++i )
233 bool res = testImageContainerBenchmark();
234 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;