DGtal 1.4.0
Loading...
Searching...
No Matches
testMetrics-benchmark.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
#include "DGtal/geometry/volumes/distance/InexactPredicateLpSeparableMetric.h"
#include <boost/lexical_cast.hpp>
Include dependency graph for testMetrics-benchmark.cpp:

Go to the source code of this file.

Functions

template<int p>
bool runATest (unsigned int maxTest)
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/11/03

Functions for testing class Metrics-benchmark.

This file is part of the DGtal library.

Definition in file testMetrics-benchmark.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 97 of file testMetrics-benchmark.cpp.

98{
99 trace.beginBlock ( "Testing class Metrics-benchmark" );
100 trace.info() << "Args:";
101 for ( int i = 0; i < argc; ++i )
102 trace.info() << " " << argv[ i ];
103 trace.info() << endl;
104
105 bool res = runATest<2>(1000000) &&
106 runATest<4>(10000000);
107 runATest<6>(1000000);
108 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
109 trace.endBlock();
110 return res ? 0 : 1;
111}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition Common.h:153
bool runATest(unsigned int maxTest)

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), runATest(), and DGtal::trace.

◆ runATest()

template<int p>
bool runATest ( unsigned int maxTest)

Definition at line 47 of file testMetrics-benchmark.cpp.

48{
51 double sum=0.0, d=0,d2=0, MSE=0;
52 std::string txt = "Testing Exponent" + boost::lexical_cast<string>(p);
53
54
55 DGtal::Dimension dim = 1000;
56 trace.beginBlock(txt);
57 trace.beginBlock("Exact Predicate run");
58 for(unsigned int i=0; i< maxTest; ++i)
59 {
60 Z3i::Point P( rand() % dim,rand() % dim ,rand() % dim );
61 Z3i::Point Q( rand() % dim, rand() % dim, rand() % dim);
62 sum += exactMetric(P,Q);
63 }
64
66
67 trace.beginBlock("Inexact Predicate run");
68 for(unsigned int i=0; i< maxTest; ++i)
69 {
70 Z3i::Point P( rand() % dim,rand() % dim ,rand() % dim );
71 Z3i::Point Q( rand() % dim, rand() % dim, rand() % dim);
72 sum += approxMetric(P,Q);
73 }
75
76
77 trace.beginBlock("Both with comparison run");
78 for(unsigned int i=0; i< maxTest; ++i)
79 {
80 Z3i::Point P( rand() % dim,rand() % dim ,rand() % dim );
81 Z3i::Point Q( rand() % dim, rand() % dim, rand() % dim);
82 d = exactMetric(P,Q);
83 d2 = approxMetric(P,Q);
84 MSE += (d-d2)*(d-d2);
85 }
87 trace.info() << "Mean Square Error = "<<MSE<<std::endl;
89 return true;
90}
Aim: implements separable l_p metrics with exact predicates.
Aim: implements separable l_p metrics with approximated predicates.
DGtal::uint32_t Dimension
Definition Common.h:136

References DGtal::Trace::beginBlock(), dim, DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().