Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
testInHalfPlane-benchmark.cpp
Go to the documentation of this file.
1
16
27
29#include <iostream>
30#include <cstdlib>
31#include <ctime>
32
33#include "DGtal/base/Common.h"
34
35#include "DGtal/kernel/PointVector.h"
36
37#include "DGtal/geometry/tools/determinant/C2x2DetComputer.h"
38#include "DGtal/geometry/tools/determinant/Simple2x2DetComputer.h"
39#include "DGtal/geometry/tools/determinant/SimpleIncremental2x2DetComputer.h"
40#include "DGtal/geometry/tools/determinant/AvnaimEtAl2x2DetSignComputer.h"
41#include "DGtal/geometry/tools/determinant/Filtered2x2DetComputer.h"
42
43#include "DGtal/geometry/tools/determinant/COrientationFunctor2.h"
44#include "DGtal/geometry/tools/determinant/InHalfPlaneBy2x2DetComputer.h"
45#include "DGtal/geometry/tools/determinant/InHalfPlaneBySimple3x3Matrix.h"
47
48using namespace std;
49using namespace DGtal;
50
51
53// Random Functions
55
60{
61 return static_cast<DGtal::int32_t>(rand() % 32768);
62}
63
69{
70 return static_cast<DGtal::int32_t>(rand() % 2048) +
71 ( randomInt15() * 2048 );
72}
73
79{
80 return randomInt15() +
81 ( randomInt15() * 32768 );
82}
83
89{
90 return
91 static_cast<DGtal::int64_t>(rand() % 128) +
92 ( static_cast<DGtal::int64_t>(randomInt15()) +
93 ( static_cast<DGtal::int64_t>(randomInt30()) )
94 * 32768 )
95 * 128;
96}
97
103{
104 return
105 static_cast<double>(rand() % 128) +
106 ( static_cast<double>(randomInt15()) +
107 ( static_cast<double>(randomInt30()) )
108 * 32768 )
109 * 128;
110}
111
117{
118 return
119 static_cast<DGtal::int64_t>(rand() % 4) +
120 ( static_cast<DGtal::int64_t>(randomInt30()) +
121 ( static_cast<DGtal::int64_t>(randomInt30()) )
122 * 1073741824 )
123 * 4;
124}
125
126
132{
133 return
134 static_cast<DGtal::BigInteger>(rand() % 4) +
135 ( static_cast<DGtal::BigInteger>(randomInt30()) +
136 ( static_cast<DGtal::BigInteger>(randomInt30()) )
137 * 1073741824 )
138 * 4;
139}
140
146{
148 return ((rand() % 2) ? x : -x);
149}
150
156{
158 return ((rand() % 2) ? x : -x);
159}
160
166{
168 return ((rand() % 2) ? x : -x);
169}
170
176{
178 return ((rand() % 2) ? x : -x);
179}
180
186{
187 double x = randomDouble52();
188 return ((rand() % 2) ? x : -x);
189}
190
196{
198 return ((rand() % 2) ? x : -x);
199}
200
206{
208 if (rand() % 2)
209 return x;
210 else
211 return -x;
212}
213
215// Tests Functions
217
226template<typename OrientationFunctor, typename RandomFunctor>
227bool randomTest(OrientationFunctor f, RandomFunctor gen, const DGtal::int32_t n = 1000000)
228{
230
231 typedef typename OrientationFunctor::Point Point;
232 Point P, Q, R;
233
234 clock_t timeBegin, timeEnd;
235 timeBegin = clock();
236
237 for (DGtal::int32_t i = 0; (i < n); ++i)
238 {
239 P[0] = gen();
240 P[1] = gen();
241 Q[0] = gen();
242 Q[1] = gen();
243 f.init(P, Q);
244 R[0] = gen();
245 R[1] = gen();
246 f( R );
247 }
248
249 timeEnd = clock();
250 long double time, CPUTime;
251 time = ((double)timeEnd-(double)timeBegin);
252 CPUTime = time/((double)CLOCKS_PER_SEC);
253 std::cout << CPUTime << " ";
254
255 return true;
256}
257
268template<typename OrientationFunctor, typename RandomFunctor>
269bool nullSameVectorsTest(OrientationFunctor f, RandomFunctor gen, const DGtal::int32_t n = 1000000)
270{
272
273 typedef typename OrientationFunctor::Point Point;
274 Point P, Q;
275
276 clock_t timeBegin, timeEnd;
277 timeBegin = clock();
278
279 for (DGtal::int32_t i = 0; (i < n); ++i)
280 {
281 P[0] = gen();
282 P[1] = gen();
283 Q[0] = gen();
284 Q[1] = gen();
285 f.init(P, Q);
286 f( Q );
287 }
288
289 timeEnd = clock();
290 long double time, CPUTime;
291 time = ((double)timeEnd-(double)timeBegin);
292 CPUTime = time/((double)CLOCKS_PER_SEC);
293 std::cout << CPUTime << " ";
294
295 return true;
296}
297
308template<typename OrientationFunctor, typename RandomFunctor>
309bool nullZeroVectorTest(OrientationFunctor f, RandomFunctor gen, const DGtal::int32_t n = 1000000)
310{
312
313 typedef typename OrientationFunctor::Point Point;
314 Point P, Q;
315
316 clock_t timeBegin, timeEnd;
317 timeBegin = clock();
318
319 for (DGtal::int32_t i = 0; (i < n); ++i)
320 {
321 P[0] = gen();
322 P[1] = gen();
323 Q[0] = gen();
324 Q[1] = gen();
325 f.init(P, Q);
326 f( P );
327 }
328
329 timeEnd = clock();
330 long double time, CPUTime;
331 time = ((double)timeEnd-(double)timeBegin);
332 CPUTime = time/((double)CLOCKS_PER_SEC);
333 std::cout << CPUTime << " ";
334
335 return true;
336}
337
349template<typename OrientationFunctor, typename RandomFunctor>
350bool nullTest(OrientationFunctor f, RandomFunctor gen, const DGtal::int32_t n = 1000000)
351{
353
354 typedef typename OrientationFunctor::Point Point;
355 Point P, Q, R;
356 P = Point(0,0);
357
358 typedef typename Point::Coordinate Coordinate;
359 Coordinate k, l, u0, u1;
360
361 clock_t timeBegin, timeEnd;
362 timeBegin = clock();
363
364 for (DGtal::int32_t i = 0; (i < n); ++i)
365 {
366 k = gen();
367 l = gen();
368 u0 = gen();
369 u1 = gen();
370 Q[0] = k*u0;
371 Q[1] = k*u1;
372 R[0] = l*u0;
373 R[1] = l*u1;
374 f.init(P, Q);
375 f( R );
376 }
377
378 timeEnd = clock();
379 long double time, CPUTime;
380 time = ((double)timeEnd-(double)timeBegin);
381 CPUTime = time/((double)CLOCKS_PER_SEC);
382 std::cout << CPUTime << " ";
383
384 return true;
385}
386
399template<typename OrientationFunctor, typename RandomFunctor>
400bool quasiNullTest(OrientationFunctor f, RandomFunctor gen, const DGtal::int32_t n = 1000000)
401{
403
404 typedef typename OrientationFunctor::Point Point;
405 Point P, Q, R;
406 P = Point(0,0);
407
408 typedef typename Point::Coordinate Coordinate;
409 Coordinate k, l, u0, u1;
410
411 clock_t timeBegin, timeEnd;
412 timeBegin = clock();
413
414 for (DGtal::int32_t i = 0; (i < n); ++i)
415 {
416 k = gen();
417 l = gen();
418 u0 = gen();
419 u1 = gen();
420 Q[0] = k*u0;
421 Q[0] += (rand()%5)-2;
422 Q[1] = k*u1;
423 Q[1] += (rand()%5)-2;
424 R[0] = l*u0;
425 R[0] += (rand()%5)-2;
426 R[1] = l*u1;
427 R[1] += (rand()%5)-2;
428 f.init(P, Q);
429 f( R );
430 }
431
432 timeEnd = clock();
433 long double time, CPUTime;
434 time = ((double)timeEnd-(double)timeBegin);
435 CPUTime = time/((double)CLOCKS_PER_SEC);
436 std::cout << CPUTime << " ";
437
438 return true;
439}
440
453template<typename OrientationFunctor>
454bool incTest(OrientationFunctor f, const DGtal::int32_t n = 1000000)
455{
457
458 typedef typename OrientationFunctor::Point Point;
459 Point P, Q, R;
460
461 typedef typename Point::Coordinate Coordinate;
462 Coordinate dx, dy;
463
464 Coordinate max = 1073741824;
465 P = Point(0,0);
466 Q = Point(max, max);
467 R = Point(max/2, max/2);
468 f.init(P, Q);
469
470 clock_t timeBegin, timeEnd;
471 timeBegin = clock();
472
473 for (DGtal::int32_t i = 0; (i < n); ++i)
474 {
475 dx = (rand() % 3) - 1;
476 dy = (rand() % 3) - 1;
477 R[0] += dx;
478 ASSERT( R[0] >= -max );
479 ASSERT( R[0] < max );
480 R[1] += dy;
481 ASSERT( R[0] >= -max );
482 ASSERT( R[0] < max );
483 f( R );
484 }
485
486 timeEnd = clock();
487 long double time, CPUTime;
488 time = ((double)timeEnd-(double)timeBegin);
489 CPUTime = time/((double)CLOCKS_PER_SEC);
490 std::cout << CPUTime << " ";
491
492 return true;
493}
494
501{
503
504 long seed = time(NULL);
505
506 std::cout << "# incremental input " << std::endl;
507 std::cout << "# running times in s. for 1 million tries" << std::endl;
508
509 {
510 srand(seed);
511 std::cout << "2x2-int32-int64 ";
514 incTest( F() );
515 std::cout << std::endl;
516 }
517 {
518 srand(seed);
519 std::cout << "2x2-inc-int32-int64 ";
522 incTest( F() );
523 std::cout << std::endl;
524 }
525 {
526 srand(seed);
527 std::cout << "2x2-avnaim++-int32-double ";
528 typedef AvnaimEtAl2x2DetSignComputer<double> DetComputer;
529 typedef Filtered2x2DetComputer<DetComputer> FDetComputer;
531 incTest( F() );
532 std::cout << std::endl;
533 }
534 {
535 srand(seed);
536 std::cout << "2x2-int32-BigInt ";
539 incTest( F() );
540 std::cout << std::endl;
541 }
542 {
543 srand(seed);
544 std::cout << "2x2-inc-int32-BigInt ";
547 incTest( F() );
548 std::cout << std::endl;
549 }
550 return true;
551}
552
559{
561
562 std::cout << "# random integers within [-2^30 ; 2^30[" << std::endl;
563 std::cout << "# running times in s. for 1 million tries" << std::endl;
564 std::cout << "# columns: random, null1, null2, null3, quasi-null " << std::endl;
565 std::cout << "# NB. double has " << std::numeric_limits<double>::digits << " bits in the mantissa " << std::endl;
566
567 long seed = time(NULL);
568
569 {
570 srand(seed);
571 std::cout << "3x3-int32-int64 ";
578 std::cout << std::endl;
579 }
580 {
581 srand(seed);
582 std::cout << "3x3-int32-BigInt ";
589 std::cout << std::endl;
590}
591 {
592 srand(seed);
593 std::cout << "2x2-int32-int64 ";
601 std::cout << std::endl;
602 }
603 {
604 srand(seed);
605 std::cout << "2x2-int32-BigInt ";
613 std::cout << std::endl;
614 }
615 {
616 srand(seed);
617 std::cout << "2x2-inc-int32-int64 ";
625 std::cout << std::endl;
626 }
627 {
628 srand(seed);
629 std::cout << "2x2-inc-int32-BigInt ";
637 std::cout << std::endl;
638 }
639 {
640 srand(seed);
641 std::cout << "2x2-avnaim-int32-int32 ";
649 std::cout << std::endl;
650 }
651 {
652 srand(seed);
653 std::cout << "2x2-avnaim-int32-double ";
654 typedef AvnaimEtAl2x2DetSignComputer<double> DetComputer;
661 std::cout << std::endl;
662 }
663 {
664 srand(seed);
665 std::cout << "2x2-avnaim++-int32-double ";
666 typedef AvnaimEtAl2x2DetSignComputer<double> DetComputer;
667 typedef Filtered2x2DetComputer<DetComputer> FDetComputer;
674 std::cout << std::endl;
675 }
676
677 return true;
678}
679
686{
687 std::cout << "# random integers within [-2^52 ; 2^52[" << std::endl;
688 std::cout << "# running times in s. for 1 million tries" << std::endl;
689 std::cout << "# columns: random, null1, null2, null3, quasi-null " << std::endl;
690 std::cout << "# NB. double has " << std::numeric_limits<double>::digits << " bits in the mantissa " << std::endl;
691
692 long seed = time(NULL);
693
694 {
695 srand(seed);
696 std::cout << "3x3-double-BigInt ";
704 std::cout << std::endl;
705 }
706 {
707 srand(seed);
708 std::cout << "2x2-double-BigInt ";
717 std::cout << std::endl;
718 }
719 {
720 srand(seed);
721 std::cout << "2x2-avnaim-int64-int64 ";
730 std::cout << std::endl;
731 }
732 {
733 srand(seed);
734 std::cout << "2x2-avnaim-double-int64 ";
743 std::cout << std::endl;
744 }
745 {
746 srand(seed);
747 std::cout << "2x2-avnaim-int64-double ";
749 typedef AvnaimEtAl2x2DetSignComputer<double> DetComputer;
756 std::cout << std::endl;
757 }
758 {
759 srand(seed);
760 std::cout << "2x2-avnaim-double-double ";
762 typedef AvnaimEtAl2x2DetSignComputer<double> DetComputer;
769 std::cout << std::endl;
770 }
771 {
772 srand(seed);
773 std::cout << "2x2-avnaim++-int64-double ";
775 typedef AvnaimEtAl2x2DetSignComputer<double> DetComputer;
776 typedef Filtered2x2DetComputer<DetComputer> FDetComputer;
783 std::cout << std::endl;
784 }
785 {
786 srand(seed);
787 std::cout << "2x2-avnaim++-double-double ";
789 typedef AvnaimEtAl2x2DetSignComputer<double> DetComputer;
790 typedef Filtered2x2DetComputer<DetComputer> FDetComputer;
797 std::cout << std::endl;
798 }
799
800 return true;
801}
802
809{
810 std::cout << "# random integers within [-2^62 ; 2^62[" << std::endl;
811 std::cout << "# running times in s. for 1 million tries" << std::endl;
812 std::cout << "# columns: random, null1, null2, null3, quasi-null " << std::endl;
813 std::cout << "# NB. long double has " << std::numeric_limits<long double>::digits << " bits in the mantissa " << std::endl;
814
815 long seed = time(NULL);
816
817 {
818 srand(seed);
819 std::cout << "3x3-BigInt-BigInt ";
827 std::cout << std::endl;
828 }
829 {
830 srand(seed);
831 std::cout << "2x2-BigInt-BigInt ";
840 std::cout << std::endl;
841 }
842 {
843 srand(seed);
844 std::cout << "2x2-inc-BigInt-BigInt ";
853 std::cout << std::endl;
854 }
855 {
856 srand(seed);
857 std::cout << "2x2-avnaim-int64-int64 ";
866 std::cout << std::endl;
867 }
868 {
869 srand(seed);
870 std::cout << "2x2-avnaim++-int64-longdouble ";
873 typedef Filtered2x2DetComputer<DetComputer> FDetComputer;
880 std::cout << std::endl;
881 }
882
883 return true;
884}
885
887// Standard services - public :
888
889int main( int argc, char** argv )
890{
891 trace.beginBlock ( "Testing class InHalfPlane-benchmark" );
892 trace.info() << "Args:";
893 for ( int i = 0; i < argc; ++i )
894 trace.info() << " " << argv[ i ];
895 trace.info() << endl;
896
901
902 bool res = true;
903 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
904 trace.endBlock();
905 return res ? 0 : 1;
906}
907// //
Aim: Class that provides a way of computing the sign of the determinant of a 2x2 matrix from its four...
Aim: Class that provides a way of computing the sign of the determinant of a 2x2 matrix from its four...
Aim: Class that implements an orientation functor, ie. it provides a way to compute the orientation o...
Aim: Class that implements an orientation functor, ie. it provides a way to compute the orientation o...
Aim: Implements basic operations that will be used in Point and Vector classes.
Aim: Small class useful to compute the determinant of a 2x2 matrix from its four coefficients,...
Aim: Small class useful to compute, in an incremental way, the determinant of a 2x2 matrix from its f...
DGtal is the top-level namespace which contains all DGtal functions and types.
std::int32_t int32_t
signed 32-bit integer.
Definition BasicTypes.h:71
std::int64_t int64_t
signed 94-bit integer.
Definition BasicTypes.h:73
Trace trace
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>, boost::multiprecision::et_off > BigInteger
Definition BasicTypes.h:75
STL namespace.
Aim: This concept is a refinement of COrientationFunctor, useful for simple algebraic curves that can...
int max(int a, int b)
int main()
Definition testBits.cpp:56
MyPointD Point
srand(0)
double randomDouble52()
DGtal::int32_t randomInt15()
bool nullZeroVectorTest(OrientationFunctor f, RandomFunctor gen, const DGtal::int32_t n=1000000)
DGtal::BigInteger signedRandomBigInt62()
DGtal::int32_t randomInt30()
DGtal::int64_t signedRandomInt52()
DGtal::int32_t randomInt26()
DGtal::int64_t signedRandomInt62()
bool randomTest30All()
bool incTest(OrientationFunctor f, const DGtal::int32_t n=1000000)
DGtal::int64_t randomInt52()
bool incTestComparison()
DGtal::int32_t signedRandomInt30()
DGtal::int32_t signedRandomInt15()
bool randomTest(OrientationFunctor f, RandomFunctor gen, const DGtal::int32_t n=1000000)
double signedRandomDouble52()
bool quasiNullTest(OrientationFunctor f, RandomFunctor gen, const DGtal::int32_t n=1000000)
DGtal::int64_t randomInt62()
bool randomTest62All()
bool nullSameVectorsTest(OrientationFunctor f, RandomFunctor gen, const DGtal::int32_t n=1000000)
bool randomTest52All()
DGtal::int32_t signedRandomInt26()
bool nullTest(OrientationFunctor f, RandomFunctor gen, const DGtal::int32_t n=1000000)
DGtal::BigInteger randomBigInt62()