0024750: Replace instantiations of TCollection generic classes by NCollection templat...
[occt.git] / src / QANCollection / QANCollection_Stl.cxx
CommitLineData
79a35943 1// Created on: 2014-04-16
2// Created by: Denis BOGOLEPOV
3// Copyright (c) 2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <QANCollection.hxx>
17#include <Draw_Interpretor.hxx>
18
19#include <NCollection_Array1.hxx>
20#include <NCollection_List.hxx>
21#include <NCollection_Sequence.hxx>
22#include <NCollection_Vector.hxx>
23#include <NCollection_Map.hxx>
24#include <NCollection_DataMap.hxx>
25#include <NCollection_IndexedMap.hxx>
26#include <NCollection_IndexedDataMap.hxx>
27#include <Standard_Assert.hxx>
28#include <OSD_Timer.hxx>
c7b59798 29#include <OSD_Parallel.hxx>
79a35943 30#include <algorithm>
31#include <list>
32#include <set>
33#include <typeinfo>
34#include <vector>
35
36//! Size of test data sets.
37const int THE_TEST_SIZE = 5000;
38
39namespace {
40 // Auxiliary class to use in std::random_shuffle()
41 struct RandomGenerator {
42 RandomGenerator () { srand(1); }
43 int operator () (int upper) const { return rand() % upper; }
44 };
45}
46
47template<class CollectionType, class StlType>
48struct CollectionFiller
49{
50 static void Perform (CollectionType** theCollec, Standard_Integer theSize = THE_TEST_SIZE)
51 {
52 *theCollec = new CollectionType();
53 srand(1);
54 for (Standard_Integer anIdx = 0; anIdx < theSize; ++anIdx)
55 {
56 (*theCollec)->Append (rand());
57 }
58 }
59
60 static void Perform (StlType** theVector,
61 CollectionType** theCollec, Standard_Integer theSize = THE_TEST_SIZE)
62 {
63 CollectionFiller::Perform (theCollec, theSize);
64
65 *theVector = new StlType ((*theCollec)->begin(), (*theCollec)->end());
66 }
67};
68
69template<class T, typename StlType>
70struct CollectionFiller<NCollection_Array1<T>, StlType>
71{
72 static void Perform (NCollection_Array1<T>** theCollec,
73 Standard_Integer theSize = THE_TEST_SIZE)
74 {
75 *theCollec = new NCollection_Array1<T> (0, theSize - 1);
76 srand (1);
77 for (Standard_Integer anIdx = 0; anIdx < theSize; ++anIdx)
78 {
79 (*theCollec)->ChangeValue (anIdx) = rand();
80 }
81 }
82
83 static void Perform (StlType** theVector,
84 NCollection_Array1<T>** theCollec, Standard_Integer theSize = THE_TEST_SIZE)
85 {
86 CollectionFiller<NCollection_Array1<T>, StlType >::Perform (theCollec, theSize);
87
88 *theVector = new StlType ((*theCollec)->begin(), (*theCollec)->end());
89 }
90};
91
92template<class CollectionType, class T>
93struct MapFiller
94{
95 static void Perform (CollectionType** theCollec, Standard_Integer theSize = THE_TEST_SIZE)
96 {
97 *theCollec = new CollectionType();
98 srand(1);
99 for (Standard_Integer anIdx = 0; anIdx < theSize; ++anIdx)
100 {
101 (*theCollec)->Add (rand());
102 }
103 }
104};
105
106template<class T>
107struct MapFiller<NCollection_DataMap<T, T>, T>
108{
109 static void Perform (NCollection_DataMap<T, T>** theCollec1,
110 NCollection_DataMap<T, T>** theCollec2 = NULL, Standard_Integer theSize = THE_TEST_SIZE)
111 {
112 *theCollec1 = new NCollection_DataMap<T, T>();
113
114 if (theCollec2 != NULL)
115 *theCollec2 = new NCollection_DataMap<T, T>();
116 srand(1);
117 for (Standard_Integer anIdx = 0; anIdx < theSize; ++anIdx)
118 {
119 const T aVal1 = rand();
120 const T aVal2 = rand();
121
122 (*theCollec1)->Bind (aVal1, aVal2);
123
124 if (theCollec2 != NULL)
125 (*theCollec2)->Bind (aVal1, aVal2);
126 }
127 }
128};
129
130template<class T>
131struct MapFiller<NCollection_IndexedDataMap<T, T>, T>
132{
133 static void Perform (NCollection_IndexedDataMap<T, T>** theCollec1,
134 NCollection_IndexedDataMap<T, T>** theCollec2 = NULL, Standard_Integer theSize = THE_TEST_SIZE)
135 {
136 *theCollec1 = new NCollection_IndexedDataMap<T, T>();
137
138 if (theCollec2 != NULL)
139 *theCollec2 = new NCollection_IndexedDataMap<T, T>();
140 srand(1);
141 for (Standard_Integer anIdx = 0; anIdx < theSize; ++anIdx)
142 {
143 const T aVal1 = rand();
144 const T aVal2 = rand();
145
146 (*theCollec1)->Add (aVal1, aVal2);
147
148 if (theCollec2 != NULL)
149 (*theCollec2)->Add (aVal1, aVal2);
150 }
151 }
152};
153
154//=======================================================================
155//function : TestIteration
156//purpose :
157//=======================================================================
158template<class CollectionType, class StlType>
159Standard_Boolean TestIteration()
160{
161 StlType* aVector (NULL);
162 CollectionType* aCollec (NULL);
163
164 CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec);
165
166 typename StlType::iterator aVecIter = aVector->begin();
167 typename CollectionType::iterator aColIter = aCollec->begin();
168
169 Standard_Boolean aResult (Standard_True);
170
171 for (; aVecIter != aVector->end(); ++aVecIter, ++aColIter)
172 {
173 if (*aVecIter != *aColIter)
174 aResult = Standard_False;
175 }
176
177 if (aColIter != aCollec->end())
178 {
179 aResult = Standard_False;
180 }
181
182 delete aVector;
183 delete aCollec;
184
185 return aResult;
186}
187
188//=======================================================================
189//function : TestMinMax
190//purpose :
191//=======================================================================
192template<class CollectionType, class StlType>
193Standard_Boolean TestMinMax()
194{
195 StlType* aVector (NULL);
196 CollectionType* aCollec (NULL);
197
198 CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec);
199
200 typename StlType::value_type aValue1 = *std::min_element (aVector->begin(), aVector->end());
201 typename CollectionType::value_type aValue2 = *std::min_element (aCollec->begin(), aCollec->end());
202
203 Standard_Boolean aResult (Standard_True);
204
205 if (aValue1 != aValue2)
206 aResult = Standard_False;
207
208 aValue1 = *std::max_element (aVector->begin(), aVector->end());
209 aValue2 = *std::max_element (aCollec->begin(), aCollec->end());
210
211 if (aValue1 != aValue2)
212 aResult = Standard_False;
213
214 delete aVector;
215 delete aCollec;
216
217 return aResult;
218}
219
220//=======================================================================
221//function : TestReplace
222//purpose :
223//=======================================================================
224template<class CollectionType, class StlType>
225Standard_Boolean TestReplace()
226{
227 StlType* aVector (NULL);
228 CollectionType* aCollec (NULL);
229
230 CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec);
231
232 const typename StlType::value_type aValue = aVector->back();
233
234 std::replace (aVector->begin(), aVector->end(), aValue, static_cast<typename StlType::value_type> (-1));
235 std::replace (aCollec->begin(), aCollec->end(), aValue, static_cast<typename CollectionType::value_type> (-1));
236
237 typename StlType::iterator aVecIter = aVector->begin();
238 typename CollectionType::iterator aColIter = aCollec->begin();
239
240 Standard_Boolean aResult (Standard_True);
241
242 for (; aVecIter != aVector->end(); ++aVecIter, ++aColIter)
243 {
244 if (*aVecIter != *aColIter)
245 aResult = Standard_False;
246 }
247
248 if (aColIter != aCollec->end())
249 {
250 aResult = Standard_False;
251 }
252
253 delete aVector;
254 delete aCollec;
255
256 return aResult;
257}
258
259//=======================================================================
260//function : TestReverse
261//purpose :
262//=======================================================================
263template<class CollectionType, class StlType>
264Standard_Boolean TestReverse()
265{
266 StlType* aVector (NULL);
267 CollectionType* aCollec (NULL);
268
269 CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec);
270
271 std::reverse (aVector->begin(), aVector->end());
272 std::reverse (aCollec->begin(), aCollec->end());
273
274 typename StlType::iterator aVecIter = aVector->begin();
275 typename CollectionType::iterator aColIter = aCollec->begin();
276
277 Standard_Boolean aResult (Standard_True);
278
279 for (; aVecIter != aVector->end(); ++aVecIter, ++aColIter)
280 {
281 if (*aVecIter != *aColIter)
282 aResult = Standard_False;
283 }
284
285 if (aColIter != aCollec->end())
286 {
287 aResult = Standard_False;
288 }
289
290 delete aVector;
291 delete aCollec;
292
293 return aResult;
294}
295
296//=======================================================================
297//function : TestSort
298//purpose :
299//=======================================================================
300template<class CollectionType, class StlType>
301Standard_Boolean TestSort()
302{
303 StlType* aVector (NULL);
304 CollectionType* aCollec (NULL);
305
306 CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec);
307
308 std::sort (aVector->begin(), aVector->end());
309 std::sort (aCollec->begin(), aCollec->end());
310
311 typename StlType::iterator aVecIter = aVector->begin();
312 typename CollectionType::iterator aColIter = aCollec->begin();
313
314 Standard_Boolean aResult (Standard_True);
315
316 for (; aVecIter != aVector->end(); ++aVecIter, ++aColIter)
317 {
318 if (*aVecIter != *aColIter)
319 aResult = Standard_False;
320 }
321
322 if (aColIter != aCollec->end())
323 {
324 aResult = Standard_False;
325 }
326
327 delete aVector;
328 delete aCollec;
329
330 return aResult;
331}
332
79a35943 333template <typename T>
334struct Invoker
335{
336 void operator()(T& theValue) const
337 {
338 theValue *= 2;
339 }
340};
341
342//=======================================================================
c7b59798 343//function : TestParallel
79a35943 344//purpose :
345//=======================================================================
346template<class CollectionType, class StlType>
c7b59798 347Standard_Boolean TestParallel()
79a35943 348{
349 StlType* aVector (NULL);
350 CollectionType* aCollec (NULL);
351
352 CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec);
353
c7b59798 354 OSD_Parallel::ForEach(aVector->begin(), aVector->end(), Invoker<typename StlType::value_type>());
355 OSD_Parallel::ForEach(aCollec->begin(), aCollec->end(), Invoker<typename CollectionType::value_type>());
79a35943 356
357 typename StlType::iterator aVecIter = aVector->begin();
358 typename CollectionType::iterator aColIter = aCollec->begin();
359
360 Standard_Boolean aResult (Standard_True);
361
362 for (; aVecIter != aVector->end(); ++aVecIter, ++aColIter)
363 {
364 if (*aVecIter != *aColIter)
365 aResult = Standard_False;
366 }
367
368 if (aColIter != aCollec->end())
369 {
370 aResult = Standard_False;
371 }
372
373 delete aVector;
374 delete aCollec;
375
376 return aResult;
377}
378
379//=======================================================================
c7b59798 380//function : TestDataMapParallel
79a35943 381//purpose :
382//=======================================================================
383template<class CollectionType, class T>
c7b59798 384Standard_Boolean TestDataMapParallel()
79a35943 385{
386 CollectionType* aCollec1 (NULL);
387 CollectionType* aCollec2 (NULL);
388
389 MapFiller<CollectionType, T>::Perform (&aCollec1, &aCollec2);
390
c7b59798 391 OSD_Parallel::ForEach(aCollec1->begin(), aCollec1->end(), Invoker<T>());
79a35943 392
393 // create OCCT-style iterator
394 typename CollectionType::Iterator aOccIter (*aCollec2);
395
396 // create STL-compatible iterator
397 typename CollectionType::const_iterator aStlIter = aCollec1->cbegin();
398
399 Standard_Boolean aResult (Standard_True);
400
401 for (; aStlIter != aCollec1->cend(); ++aStlIter, aOccIter.Next())
402 {
403 if (static_cast<T> (2) * aOccIter.Value() != *aStlIter)
404 aResult = Standard_False;
405 }
406
407 if (aOccIter.More())
408 {
409 aResult = Standard_False;
410 }
411
412 delete aCollec1;
413 delete aCollec2;
414
415 return aResult;
416}
417
79a35943 418//=======================================================================
419//function : TestMapIteration
420//purpose :
421//=======================================================================
422template<class CollectionType, class T>
423Standard_Boolean TestMapIteration()
424{
425 CollectionType* aCollec (NULL);
426
427 MapFiller<CollectionType, T>::Perform (&aCollec);
428
429 // create OCCT-style iterator
430 typename CollectionType::Iterator aOccIter (*aCollec);
431
432 // create STL-compatible iterator
433 typename CollectionType::const_iterator aStlIter = aCollec->cbegin();
434
435 Standard_Boolean aResult (Standard_True);
436
437 for (; aStlIter != aCollec->cend(); ++aStlIter, aOccIter.Next())
438 {
439 if (aOccIter.Value() != *aStlIter)
440 aResult = Standard_False;
441 }
442
443 if (aOccIter.More())
444 {
445 aResult = Standard_False;
446 }
447
448 delete aCollec;
449
450 return aResult;
451}
452
453//=======================================================================
454//function : TestForwardIterator
455//purpose : test basic features of iterator (forward)
456//=======================================================================
457template <class CollectionType>
458void TestForwardIterator ()
459{
460 CollectionType* aCollec (NULL);
461
462 CollectionFiller<CollectionType, void>::Perform (&aCollec);
463
464 // test non-const iteration
465 typename CollectionType::iterator it = aCollec->begin(); // copy construction
466 typename CollectionType::iterator it2; // default constructor
467 it2 = it; // assignment
468 it2 = it++; // postfix increment
469 if (it2 == it || ! (it2 != it))
470 std::cout << "Failed " << typeid(it).name() << " equality check" << std::endl;
471 it2 = ++it; // prefix increment
472 if (it2 != it || ! (it2 == it))
473 std::cout << "Failed " << typeid(it).name() << " equality check" << std::endl;
474
475 typename CollectionType::iterator::value_type t = *it;
476 *it2 = t;
477 *(it2.operator-> ()) = t;
478
479 // test const iteration
480 typename CollectionType::const_iterator cit = aCollec->cbegin(); // copy construction
481 typename CollectionType::const_iterator cit2; // default constructor
482 cit2 = cit; // assignment
483 cit2 = cit++; // postfix increment
484 if (cit2 == cit || ! (cit2 != cit))
485 std::cout << "Failed " << typeid(cit).name() << " equality check" << std::endl;
486 cit2 = ++cit; // prefix increment
487 if (cit2 != it || ! (cit2 == cit))
488 std::cout << "Failed " << typeid(cit).name() << " equality check" << std::endl;
489
490 typename CollectionType::const_iterator::value_type ct = *cit;
491 ct = *cit;
492// *cit2 = ct;
493// *(cit2.operator-> ()) = t;
494
495 delete aCollec;
496}
497
498//=======================================================================
499//function : TestBidirIterator
500//purpose : test features of bidirectional iterator
501//=======================================================================
502template <class CollectionType>
503void TestBidirIterator ()
504{
505 CollectionType* aCollec (NULL);
506
507 CollectionFiller<CollectionType, void>::Perform (&aCollec);
508
509 // test non-const iteration
510 typename CollectionType::iterator it = aCollec->end(); // copy construction
511 typename CollectionType::iterator it2 = it--; // postfix decrement
512 if (it2 == it || ! (it2 != it))
513 std::cout << "Failed " << typeid(it).name() << " equality check" << std::endl;
514 it2 = --it; // prefix decrement
515 if (it2 != it || ! (it2 == it))
516 std::cout << "Failed " << typeid(it).name() << " equality check" << std::endl;
517
518 delete aCollec;
519}
520
521//=======================================================================
522//function : TestRandomIterator
523//purpose : test features of random iterator
524//=======================================================================
525template <class CollectionType>
526void TestRandomIterator ()
527{
528 CollectionType* aCollec (NULL);
529
530 CollectionFiller<CollectionType, void>::Perform (&aCollec);
531
532 // test non-const iteration
533 typename CollectionType::iterator it = aCollec->begin(); // copy construction
534 typename CollectionType::iterator it2 = it + 5;
535 if ((it2 - it) != 5)
536 std::cout << "Failed " << typeid(it).name() << " arithmetics" << std::endl;
537 if (it2 < it || it2 <= it || ! (it2 > it) || ! (it2 >= it))
538 std::cout << "Failed " << typeid(it).name() << " comparison" << std::endl;
539 it += 5;
540 if (it2 != it)
541 std::cout << "Failed " << typeid(it).name() << " arithmetics" << std::endl;
542 it2 = it - 5;
543 if ((it2 - it) != -5)
544 std::cout << "Failed " << typeid(it).name() << " arithmetics" << std::endl;
545 if (it2 > it || it2 >= it || ! (it2 < it) || ! (it2 <= it))
546 std::cout << "Failed " << typeid(it).name() << " comparison" << std::endl;
547 it -= 5;
548 if (it2 != it)
549 std::cout << "Failed " << typeid(it).name() << " arithmetics" << std::endl;
550
551 typename CollectionType::value_type t = it[5]; // offset dereference
552 *it = t;
553
554 delete aCollec;
555}
556
557//=======================================================================
558//function : QANListStlIterator
559//purpose :
560//=======================================================================
561static Standard_Integer QANListStlIterator (Draw_Interpretor&, Standard_Integer, const char**)
562{
563 // compile-time tests
564 TestForwardIterator <NCollection_List<Standard_Integer> >();
565
566 // run-time tests
567 Standard_Boolean aResult = TestIteration<NCollection_List<int>, std::list<int> >();
568 std::cout << "NCollection_List<int> Iteration: " <<
569 (aResult ? "SUCCESS" : "FAIL") << std::endl;
570
571 aResult = TestIteration<NCollection_List<double>, std::list<double> >();
572 std::cout << "NCollection_List<double> Iteration: " <<
573 (aResult ? "SUCCESS" : "FAIL") << std::endl;
574
575 aResult = TestMinMax<NCollection_List<int>, std::list<int> >();
576 std::cout << "NCollection_List<int> Min-Max: " <<
577 (aResult ? "SUCCESS" : "FAIL") << std::endl;
578
579 aResult = TestMinMax<NCollection_List<double>, std::list<double> >();
580 std::cout << "NCollection_List<double> Min-Max: " <<
581 (aResult ? "SUCCESS" : "FAIL") << std::endl;
582
583 aResult = TestReplace<NCollection_List<int>, std::list<int> >();
584 std::cout << "NCollection_List<int> Replace: " <<
585 (aResult ? "SUCCESS" : "FAIL") << std::endl;
586
587 aResult = TestReplace<NCollection_List<double>, std::list<double> >();
588 std::cout << "NCollection_List<double> Replace: " <<
589 (aResult ? "SUCCESS" : "FAIL") << std::endl;
590
c7b59798 591 aResult = TestParallel< NCollection_List<int>, std::list<int> >();
592 std::cout << "NCollection_List<int> Parallel: " <<
79a35943 593 (aResult ? "SUCCESS" : "FAIL") << std::endl;
594
c7b59798 595 aResult = TestParallel<NCollection_List<double>, std::list<double> >();
596 std::cout << "NCollection_List<double> Parallel: " <<
79a35943 597 (aResult ? "SUCCESS" : "FAIL") << std::endl;
598
79a35943 599 return 0;
600}
601
602//=======================================================================
603//function : QANMapStlIterator
604//purpose :
605//=======================================================================
606static Standard_Integer QANMapStlIterator (Draw_Interpretor&, Standard_Integer, const char**)
607{
608 // compile-time tests
609// TestForwardIterator <NCollection_Map<Standard_Integer> >();
610
611 // run-time tests
612 Standard_Boolean aResult = TestMapIteration<NCollection_Map<Standard_Integer>, Standard_Integer>();
613 std::cout << "NCollection_Map<int> Iteration: " <<
614 (aResult ? "SUCCESS" : "FAIL") << std::endl;
615
616 aResult = TestMapIteration<NCollection_Map<Standard_Real>, Standard_Real>();
617 std::cout << "NCollection_Map<double> Iteration: " <<
618 (aResult ? "SUCCESS" : "FAIL") << std::endl;
619
620 return 0;
621}
622
623//=======================================================================
624//function : QANIndexedMapStlIterator
625//purpose :
626//=======================================================================
627static Standard_Integer QANIndexedMapStlIterator (Draw_Interpretor&, Standard_Integer, const char**)
628{
629 // compile-time tests
630// TestForwardIterator <NCollection_IndexedMap<Standard_Integer> >();
631// TestBidirIterator <NCollection_IndexedMap<Standard_Integer> >();
632
633 // run-time tests
634 Standard_Boolean aResult = TestMapIteration<NCollection_IndexedMap<Standard_Integer>, Standard_Integer>();
635 std::cout << "NCollection_IndexedMap<int> Iteration: " <<
636 (aResult ? "SUCCESS" : "FAIL") << std::endl;
637
638 aResult = TestMapIteration<NCollection_IndexedMap<Standard_Real>, Standard_Real>();
639 std::cout << "NCollection_IndexedMap<double> Iteration: " <<
640 (aResult ? "SUCCESS" : "FAIL") << std::endl;
641
642 return 0;
643}
644
645//=======================================================================
646//function : QANDataMapStlIterator
647//purpose :
648//=======================================================================
649static Standard_Integer QANDataMapStlIterator (Draw_Interpretor&, Standard_Integer, const char**)
650{
651 // compile-time tests
652// TestForwardIterator <NCollection_DataMap<int, int> >();
653// TestBidirIterator <NCollection_DataMap<int, int> >();
654
655 // run-time tests
656 Standard_Boolean aResult = TestMapIteration<NCollection_DataMap<Standard_Integer, Standard_Integer>, Standard_Integer>();
657 std::cout << "NCollection_DataMap<int> Iteration: " <<
658 (aResult ? "SUCCESS" : "FAIL") << std::endl;
659
660 aResult = TestMapIteration<NCollection_DataMap<Standard_Real, Standard_Real>, Standard_Real>();
661 std::cout << "NCollection_DataMap<double> Iteration: " <<
662 (aResult ? "SUCCESS" : "FAIL") << std::endl;
663
c7b59798 664 aResult = TestDataMapParallel<NCollection_DataMap<Standard_Integer, Standard_Integer>, Standard_Integer>();
665 std::cout << "NCollection_DataMap<int> Parallel: " <<
79a35943 666 (aResult ? "SUCCESS" : "FAIL") << std::endl;
667
c7b59798 668 aResult = TestDataMapParallel<NCollection_DataMap<Standard_Real, Standard_Real>, Standard_Real>();
669 std::cout << "NCollection_DataMap<double> Parallel: " <<
79a35943 670 (aResult ? "SUCCESS" : "FAIL") << std::endl;
671
79a35943 672 return 0;
673}
674
675//=======================================================================
676//function : QANIndexedDataMapStlIterator
677//purpose :
678//=======================================================================
679static Standard_Integer QANIndexedDataMapStlIterator (Draw_Interpretor&, Standard_Integer, const char**)
680{
681 // compile-time tests
682// TestForwardIterator <NCollection_IndexedDataMap<int, int> >();
683// TestBidirIterator <NCollection_IndexedDataMap<int, int> >();
684
685 // run-time tests
686 Standard_Boolean aResult = TestMapIteration<NCollection_IndexedDataMap<Standard_Integer, Standard_Integer>, Standard_Integer>();
687 std::cout << "NCollection_IndexedDataMap<int> Iteration: " <<
688 (aResult ? "SUCCESS" : "FAIL") << std::endl;
689
690 aResult = TestMapIteration<NCollection_IndexedDataMap<Standard_Real, Standard_Real>, Standard_Real>();
691 std::cout << "NCollection_IndexedDataMap<double> Iteration: " <<
692 (aResult ? "SUCCESS" : "FAIL") << std::endl;
693
c7b59798 694 aResult = TestDataMapParallel<NCollection_IndexedDataMap<Standard_Integer, Standard_Integer>, Standard_Integer>();
695 std::cout << "NCollection_IndexedDataMap<int> Parallel: " <<
79a35943 696 (aResult ? "SUCCESS" : "FAIL") << std::endl;
697
c7b59798 698 aResult = TestDataMapParallel<NCollection_IndexedDataMap<Standard_Real, Standard_Real>, Standard_Real>();
699 std::cout << "NCollection_IndexedDataMap<double> Parallel: " <<
79a35943 700 (aResult ? "SUCCESS" : "FAIL") << std::endl;
701
79a35943 702 return 0;
703}
704
705//=======================================================================
706//function : QANSequenceStlIterator
707//purpose :
708//=======================================================================
709static Standard_Integer QANSequenceStlIterator (Draw_Interpretor&, Standard_Integer, const char**)
710{
711 // compile-time tests
712 TestForwardIterator <NCollection_Sequence<int> >();
713 TestBidirIterator <NCollection_Sequence<int> >();
714
715 // run-time tests
716 Standard_Boolean aResult = TestIteration<NCollection_Sequence<int>, std::list<int> >();
717 std::cout << "NCollection_Sequence<int> Iteration: " <<
718 (aResult ? "SUCCESS" : "FAIL") << std::endl;
719
720 aResult = TestIteration<NCollection_Sequence<double>, std::list<double> >();
721 std::cout << "NCollection_Sequence<double> Iteration: " <<
722 (aResult ? "SUCCESS" : "FAIL") << std::endl;
723
724 aResult = TestMinMax<NCollection_Sequence<int>, std::list<int> >();
725 std::cout << "NCollection_Sequence<int> Min-Max: " <<
726 (aResult ? "SUCCESS" : "FAIL") << std::endl;
727
728 aResult = TestMinMax<NCollection_Sequence<double>, std::list<double> >();
729 std::cout << "NCollection_Sequence<double> Min-Max: " <<
730 (aResult ? "SUCCESS" : "FAIL") << std::endl;
731
732 aResult = TestReplace<NCollection_Sequence<int>, std::list<int> >();
733 std::cout << "NCollection_Sequence<int> Replace: " <<
734 (aResult ? "SUCCESS" : "FAIL") << std::endl;
735
736 aResult = TestReplace<NCollection_Sequence<double>, std::list<double> >();
737 std::cout << "NCollection_Sequence<double> Replace: " <<
738 (aResult ? "SUCCESS" : "FAIL") << std::endl;
739
740 aResult = TestReverse<NCollection_Sequence<int>, std::list<int> >();
741 std::cout << "NCollection_Sequence<int> Reverse: " <<
742 (aResult ? "SUCCESS" : "FAIL") << std::endl;
743
744 aResult = TestReverse<NCollection_Sequence<double>, std::list<double> >();
745 std::cout << "NCollection_Sequence<double> Reverse: " <<
746 (aResult ? "SUCCESS" : "FAIL") << std::endl;
747
c7b59798 748 aResult = TestParallel<NCollection_Sequence<int>, std::list<int> >();
749 std::cout << "NCollection_Sequence<int> Parallel: " <<
79a35943 750 (aResult ? "SUCCESS" : "FAIL") << std::endl;
751
c7b59798 752 aResult = TestParallel<NCollection_Sequence<double>, std::list<double> >();
753 std::cout << "NCollection_Sequence<double> Parallel: " <<
79a35943 754 (aResult ? "SUCCESS" : "FAIL") << std::endl;
755
79a35943 756 return 0;
757}
758
759//=======================================================================
760//function : QANVectorStlIterator
761//purpose :
762//=======================================================================
763static Standard_Integer QANVectorStlIterator (Draw_Interpretor&, Standard_Integer, const char**)
764{
765 // compile-time tests
766 TestForwardIterator <NCollection_Vector<int> >();
767 TestBidirIterator <NCollection_Vector<int> >();
768 TestRandomIterator <NCollection_Vector<int> >();
769
770 // run-time tests
771 Standard_Boolean aResult = TestIteration<NCollection_Vector<int>, std::vector<int> >();
772 std::cout << "NCollection_Vector<int> Iteration: " <<
773 (aResult ? "SUCCESS" : "FAIL") << std::endl;
774
775 aResult = TestIteration<NCollection_Vector<double>, std::vector<double> >();
776 std::cout << "NCollection_Vector<double> Iteration: " <<
777 (aResult ? "SUCCESS" : "FAIL") << std::endl;
778
779 aResult = TestMinMax<NCollection_Vector<int>, std::vector<int> >();
780 std::cout << "NCollection_Vector<int> Min-Max: " <<
781 (aResult ? "SUCCESS" : "FAIL") << std::endl;
782
783 aResult = TestMinMax<NCollection_Vector<double>, std::vector<double> >();
784 std::cout << "NCollection_Vector<double> Min-Max: " <<
785 (aResult ? "SUCCESS" : "FAIL") << std::endl;
786
787 aResult = TestReplace<NCollection_Vector<int>, std::vector<int> >();
788 std::cout << "NCollection_Vector<int> Replace: " <<
789 (aResult ? "SUCCESS" : "FAIL") << std::endl;
790
791 aResult = TestReplace<NCollection_Vector<double>, std::vector<double> >();
792 std::cout << "NCollection_Vector<double> Replace: " <<
793 (aResult ? "SUCCESS" : "FAIL") << std::endl;
794
795 aResult = TestReverse<NCollection_Vector<int>, std::vector<int> >();
796 std::cout << "NCollection_Vector<int> Reverse: " <<
797 (aResult ? "SUCCESS" : "FAIL") << std::endl;
798
799 aResult = TestReverse<NCollection_Vector<double>, std::vector<double> >();
800 std::cout << "NCollection_Vector<double> Reverse: " <<
801 (aResult ? "SUCCESS" : "FAIL") << std::endl;
802
803 aResult = TestSort<NCollection_Vector<int>, std::vector<int> >();
804 std::cout << "NCollection_Vector<int> Sort: " <<
805 (aResult ? "SUCCESS" : "FAIL") << std::endl;
806
807 aResult = TestSort<NCollection_Vector<double>, std::vector<double> >();
808 std::cout << "NCollection_Vector<double> Sort: " <<
809 (aResult ? "SUCCESS" : "FAIL") << std::endl;
810
c7b59798 811 aResult = TestParallel<NCollection_Vector<int>, std::vector<int> >();
812 std::cout << "NCollection_Vector<int> Parallel: " <<
79a35943 813 (aResult ? "SUCCESS" : "FAIL") << std::endl;
814
c7b59798 815 aResult = TestParallel<NCollection_Vector<double>, std::vector<double> >();
816 std::cout << "NCollection_Vector<double> Parallel: " <<
79a35943 817 (aResult ? "SUCCESS" : "FAIL") << std::endl;
818
79a35943 819 return 0;
820}
821
822//=======================================================================
823//function : QANArray1StlIterator
824//purpose :
825//=======================================================================
826static Standard_Integer QANArray1StlIterator (Draw_Interpretor&, Standard_Integer, const char**)
827{
828 // compile-time tests
829 TestForwardIterator <NCollection_Vector<int> >();
830 TestBidirIterator <NCollection_Vector<int> >();
831 TestRandomIterator <NCollection_Vector<int> >();
832
833 // run-time tests
834 Standard_Boolean aResult = TestIteration<NCollection_Array1<int>, std::vector<int> >();
835 std::cout << "NCollection_Array1<int> Iteration: " <<
836 (aResult ? "SUCCESS" : "FAIL") << std::endl;
837
838 aResult = TestIteration<NCollection_Array1<double>, std::vector<double> >();
839 std::cout << "NCollection_Array1<double> Iteration: " <<
840 (aResult ? "SUCCESS" : "FAIL") << std::endl;
841
842 aResult = TestMinMax<NCollection_Array1<int>, std::vector<int> >();
843 std::cout << "NCollection_Array1<int> Min-Max: " <<
844 (aResult ? "SUCCESS" : "FAIL") << std::endl;
845
846 aResult = TestMinMax<NCollection_Array1<double>, std::vector<double> >();
847 std::cout << "NCollection_Array1<double> Min-Max: " <<
848 (aResult ? "SUCCESS" : "FAIL") << std::endl;
849
850 aResult = TestReplace<NCollection_Array1<int>, std::vector<int> >();
851 std::cout << "NCollection_Array1<int> Replace: " <<
852 (aResult ? "SUCCESS" : "FAIL") << std::endl;
853
854 aResult = TestReplace<NCollection_Array1<double>, std::vector<double> >();
855 std::cout << "NCollection_Array1<double> Replace: " <<
856 (aResult ? "SUCCESS" : "FAIL") << std::endl;
857
858 aResult = TestReverse<NCollection_Array1<int>, std::vector<int> >();
859 std::cout << "NCollection_Array1<int> Reverse: " <<
860 (aResult ? "SUCCESS" : "FAIL") << std::endl;
861
862 aResult = TestReverse<NCollection_Array1<double>, std::vector<double> >();
863 std::cout << "NCollection_Array1<double> Reverse: " <<
864 (aResult ? "SUCCESS" : "FAIL") << std::endl;
865
866 aResult = TestSort<NCollection_Array1<int>, std::vector<int> >();
867 std::cout << "NCollection_Array1<int> Sort: " <<
868 (aResult ? "SUCCESS" : "FAIL") << std::endl;
869
870 aResult = TestSort<NCollection_Array1<double>, std::vector<double> >();
871 std::cout << "NCollection_Array1<double> Sort: " <<
872 (aResult ? "SUCCESS" : "FAIL") << std::endl;
873
c7b59798 874 aResult = TestParallel<NCollection_Array1<int>, std::vector<int> >();
875 std::cout << "NCollection_Array1<int> Parallel: " <<
79a35943 876 (aResult ? "SUCCESS" : "FAIL") << std::endl;
877
c7b59798 878 aResult = TestParallel<NCollection_Array1<double>, std::vector<double> >();
879 std::cout << "NCollection_Array1<double> Parallel: " <<
79a35943 880 (aResult ? "SUCCESS" : "FAIL") << std::endl;
881
79a35943 882 return 0;
883}
884
885//=======================================================================
886//function : QANTestStlIterators
887//purpose :
888//=======================================================================
889static Standard_Integer QANTestStlIterators (
890 Draw_Interpretor& theInterpretor, Standard_Integer, const char**)
891{
892 QANListStlIterator (theInterpretor, 0, NULL);
893 QANArray1StlIterator (theInterpretor, 0, NULL);
894 QANVectorStlIterator (theInterpretor, 0, NULL);
895 QANSequenceStlIterator (theInterpretor, 0, NULL);
896 QANMapStlIterator (theInterpretor, 0, NULL);
897 QANDataMapStlIterator (theInterpretor, 0, NULL);
898 QANIndexedMapStlIterator (theInterpretor, 0, NULL);
899 QANIndexedDataMapStlIterator (theInterpretor, 0, NULL);
900
901 return 0;
902}
903
904//=======================================================================
905//function : TestPerformanceRandomIterator
906//purpose :
907//=======================================================================
908template<class CollectionType, class StlType>
618617fe 909void TestPerformanceRandomIterator(Draw_Interpretor& di)
79a35943 910{
911 OSD_Timer aTimer;
912
913 StlType* aVector (NULL);
914 CollectionType* aCollec (NULL);
915
916 for (Standard_Integer aSize = 10000; aSize <= 1280000; aSize *= 2)
917 {
918 CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec, aSize);
919
920 aTimer.Reset();
921 aTimer.Start();
922 {
923 RandomGenerator aRandomGen;
924 for (Standard_Integer anIdx = 0; anIdx < 10; ++anIdx)
925 {
926 std::sort (aVector->begin(), aVector->end());
927 std::random_shuffle (aVector->begin(), aVector->end(), aRandomGen);
928 }
929 }
930 aTimer.Stop();
931
932 Standard_Real aStlTime = aTimer.ElapsedTime();
933
934 aTimer.Reset();
935 aTimer.Start();
936 {
937 RandomGenerator aRandomGen;
938 for (Standard_Integer anIdx = 0; anIdx < 10; ++anIdx)
939 {
940 std::sort (aCollec->begin(), aCollec->end());
941 std::random_shuffle (aCollec->begin(), aCollec->end(), aRandomGen);
942 }
943 }
944 aTimer.Stop();
945
946 Standard_Real aOccTime = aTimer.ElapsedTime();
947
618617fe 948 di << aSize << "\t" << aStlTime << "\t" <<
949 aOccTime << "\t" << aOccTime / aStlTime << "\n";
79a35943 950
951 // check that result is the same
952 if ( ! std::equal (aVector->begin(), aVector->end(), aCollec->begin()) )
618617fe 953 di << "Error: sequences are not the same at the end!" << "\n";
79a35943 954
955 delete aVector;
956 delete aCollec;
957 }
958}
959
960//=======================================================================
961//function : TestPerformanceForwardIterator
962//purpose :
963//=======================================================================
964template<class CollectionType, class StlType>
618617fe 965void TestPerformanceForwardIterator(Draw_Interpretor& di)
79a35943 966{
967 OSD_Timer aTimer;
968
969 StlType* aVector = 0;
970 CollectionType* aCollec = 0;
971
972 for (Standard_Integer aSize = 10000; aSize <= 1280000; aSize *= 2)
973 {
974 CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec, aSize);
975
976 aTimer.Reset();
977 aTimer.Start();
978 {
979 for (Standard_Integer anIdx = 0; anIdx < 1000; ++anIdx)
980 {
981 std::replace (aVector->begin(), aVector->end(), *aVector->begin(), static_cast<typename StlType::value_type> (anIdx));
982 }
983 }
984 aTimer.Stop();
985
986 Standard_Real aStlTime = aTimer.ElapsedTime();
987
988 aTimer.Reset();
989 aTimer.Start();
990 {
991 for (Standard_Integer anIdx = 0; anIdx < 1000; ++anIdx)
992 {
993 std::replace (aCollec->begin(), aCollec->end(), *aCollec->begin(), static_cast<typename CollectionType::value_type> (anIdx));
994 }
995 }
996 aTimer.Stop();
997
998 Standard_Real aOccTime = aTimer.ElapsedTime();
999
618617fe 1000 di << aSize << "\t" << aStlTime << "\t" <<
1001 aOccTime << "\t" << aOccTime / aStlTime << "\n";
79a35943 1002
1003 // check that result is the same
1004 if ( ! std::equal (aVector->begin(), aVector->end(), aCollec->begin()) )
618617fe 1005 di << "Error: sequences are not the same at the end!" << "\n";
79a35943 1006
1007 delete aVector;
1008 delete aCollec;
1009 }
1010}
1011
1012//=======================================================================
1013//function : TestPerformanceBidirIterator
1014//purpose :
1015//=======================================================================
1016template<class CollectionType, class StlType>
618617fe 1017void TestPerformanceBidirIterator(Draw_Interpretor& di)
79a35943 1018{
1019 OSD_Timer aTimer;
1020
1021 StlType* aVector = 0;
1022 CollectionType* aCollec = 0;
1023
1024 for (Standard_Integer aSize = 10000; aSize <= 1280000; aSize *= 2)
1025 {
1026 CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec, aSize);
1027
1028 aTimer.Reset();
1029 aTimer.Start();
1030 {
1031 for (Standard_Integer anIdx = 0; anIdx < 1000; ++anIdx)
1032 {
1033 std::reverse (aVector->begin(), aVector->end());
1034 }
1035 }
1036 aTimer.Stop();
1037
1038 Standard_Real aStlTime = aTimer.ElapsedTime();
1039
1040 aTimer.Reset();
1041 aTimer.Start();
1042 {
1043 for (Standard_Integer anIdx = 0; anIdx < 1000; ++anIdx)
1044 {
1045 std::reverse (aCollec->begin(), aCollec->end());
1046 }
1047 }
1048 aTimer.Stop();
1049
1050 Standard_Real aOccTime = aTimer.ElapsedTime();
1051
618617fe 1052 di << aSize << "\t" << aStlTime << "\t" <<
1053 aOccTime << "\t" << aOccTime / aStlTime << "\n";
79a35943 1054
1055 // check that result is the same
1056 if ( ! std::equal (aVector->begin(), aVector->end(), aCollec->begin()) )
618617fe 1057 di << "Error: sequences are not the same at the end!" << "\n";
79a35943 1058
1059 delete aVector;
1060 delete aCollec;
1061 }
1062}
1063
1064//=======================================================================
1065//function : TestPerformanceMapAccess
1066//purpose :
1067//=======================================================================
1068template<class CollectionType, class T>
618617fe 1069void TestPerformanceMapAccess(Draw_Interpretor& di)
79a35943 1070{
1071 OSD_Timer aTimer;
1072
1073 CollectionType* aCollec (NULL);
1074
1075 for (Standard_Integer aSize = 100000; aSize <= 3200000; aSize *= 2)
1076 {
1077 MapFiller<CollectionType, T>::Perform (&aCollec, aSize);
1078
1079 std::set<T> aSet (aCollec->cbegin(), aCollec->cend());
1080 std::vector<T> aVec (aCollec->cbegin(), aCollec->cend());
1081
1082 Standard_Boolean aResult = Standard_True;
1083
1084 aTimer.Reset();
1085 aTimer.Start();
1086 {
1087 for (Standard_Integer anIdx = 0; anIdx < 10000; ++anIdx)
1088 {
1089 if (aSet.find (aVec[anIdx + 1000]) == aSet.end())
1090 aResult = Standard_False;
1091 if (aSet.find (aVec[anIdx + 2000]) == aSet.end())
1092 aResult = Standard_False;
1093 if (aSet.find (aVec[anIdx + 3000]) == aSet.end())
1094 aResult = Standard_False;
1095 if (aSet.find (aVec[anIdx + 4000]) == aSet.end())
1096 aResult = Standard_False;
1097 if (aSet.find (aVec[anIdx + 5000]) == aSet.end())
1098 aResult = Standard_False;
1099 }
1100 }
1101 aTimer.Stop();
1102
1103 Standard_Real aStlTime = aTimer.ElapsedTime();
1104
1105 aTimer.Reset();
1106 aTimer.Start();
1107 {
1108 for (Standard_Integer anIdx = 0; anIdx < 10000; ++anIdx)
1109 {
1110 if (!aCollec->Contains (aVec[anIdx + 1000]))
1111 aResult = Standard_False;
1112 if (!aCollec->Contains (aVec[anIdx + 2000]))
1113 aResult = Standard_False;
1114 if (!aCollec->Contains (aVec[anIdx + 3000]))
1115 aResult = Standard_False;
1116 if (!aCollec->Contains (aVec[anIdx + 4000]))
1117 aResult = Standard_False;
1118 if (!aCollec->Contains (aVec[anIdx + 5000]))
1119 aResult = Standard_False;
1120 }
1121 }
1122 aTimer.Stop();
1123
1124 Standard_Real aOccTime = aTimer.ElapsedTime();
1125
1126 if (aResult)
1127 {
618617fe 1128 di << aSize << "\t" << aStlTime << "\t" <<
1129 aOccTime << "\t" << (aStlTime > 1e-16 ? aOccTime / aStlTime : -1) << "\n";
79a35943 1130 }
1131
1132 delete aCollec;
1133 }
1134}
1135
1136//=======================================================================
1137//function : QANTestNCollectionPerformance
1138//purpose :
1139//=======================================================================
618617fe 1140static Standard_Integer QANTestNCollectionPerformance (Draw_Interpretor& di, Standard_Integer, const char**)
79a35943 1141{
618617fe 1142 di << "Testing performance (Size | STL time | OCCT time | STL/OCCT boost)" << "\n";
79a35943 1143
618617fe 1144 di << "\n" << "std::vector vs NCollection_Array1 (sort):" << "\n\n";
1145 TestPerformanceRandomIterator<NCollection_Array1<double>, std::vector<double> >(di);
9e506120 1146
618617fe 1147 di << "\n" << "std::vector vs NCollection_Vector (sort):" << "\n\n";
1148 TestPerformanceRandomIterator<NCollection_Vector<double>, std::vector<double> >(di);
9e506120 1149
618617fe 1150 di << "\n" << "std::vector vs NCollection_Array1 (replace):" << "\n\n";
1151 TestPerformanceForwardIterator<NCollection_Array1<double>, std::vector<double> >(di);
9e506120 1152
618617fe 1153 di << "\n" << "std::vector vs NCollection_Vector (replace):" << "\n\n";
1154 TestPerformanceForwardIterator<NCollection_Vector<double>, std::vector<double> >(di);
79a35943 1155
618617fe 1156 di << "\n" << "std::list vs NCollection_List (replace):" << "\n\n";
1157 TestPerformanceForwardIterator<NCollection_List<double>, std::list<double> >(di);
79a35943 1158
618617fe 1159 di << "\n" << "std::list vs NCollection_Sequence (replace):" << "\n\n";
1160 TestPerformanceForwardIterator<NCollection_Sequence<double>, std::list<double> >(di);
79a35943 1161
618617fe 1162 di << "\n" << "std::list vs NCollection_Sequence (reverse):" << "\n\n";
1163 TestPerformanceBidirIterator<NCollection_Sequence<double>, std::list<double> >(di);
79a35943 1164
618617fe 1165 di << "\n" << "std::set vs NCollection_Map (search):" << "\n\n";
1166 TestPerformanceMapAccess<NCollection_Map<int>, int>(di);
79a35943 1167
618617fe 1168 di << "\n" << "std::set vs NCollection_IndexedMap (search):" << "\n\n";
1169 TestPerformanceMapAccess<NCollection_IndexedMap<int>, int>(di);
9e506120 1170
1171 return 0;
1172}
1173
1174//=======================================================================
1175//function : QANTestNCollectionIndexedMap
1176//purpose :
1177//=======================================================================
1178static Standard_Integer QANTestNCollectionIndexedMap (Draw_Interpretor& di, Standard_Integer, const char**)
1179{
1180 OSD_Timer aTimer;
1181
1182 std::vector<Standard_Integer> aIndxs;
1183 std::vector<Standard_Integer> aItems;
1184 NCollection_IndexedMap<Standard_Integer> aIndxMap;
1185
1186 const Standard_Integer aNbItems = 1000000;
1187
1188 srand (1);
1189 for (Standard_Integer anId = 1; anId <= aNbItems; ++anId)
1190 {
1191 const Standard_Integer aVal = anId * 2;
1192
1193 aIndxs.push_back (anId);
1194 aItems.push_back (aVal);
1195
1196 aIndxMap.Add (aVal);
1197 }
1198
1199 aTimer.Start();
1200 for (Standard_Integer anId = 0; anId < aNbItems; ++anId)
1201 {
1202 if (aIndxMap.FindIndex (aItems[anId]) != aIndxs[anId])
1203 {
1204 std::cout << "failed FindIndex\n";
1205 }
1206
1207 if (aIndxMap.FindKey (aIndxs[anId]) != aItems[anId])
1208 {
1209 std::cout << "failed FindKey\n";
1210 }
1211 }
1212 aTimer.Stop();
1213
1214 const Standard_Real aTime1 = aTimer.ElapsedTime();
1215
1216 aTimer.Reset();
1217 aTimer.Start();
1218 for (Standard_Integer anId = 0; anId < aNbItems / 30; ++anId)
1219 {
1220 const Standard_Integer anId2 = Min (aNbItems - 1,
1221 static_cast<Standard_Integer> (rand() / float (RAND_MAX) * aNbItems));
1222
1223 aIndxMap.Swap (aIndxs[anId], aIndxs[anId2]);
1224
1225 std::swap (aIndxs[anId], aIndxs[anId2]);
1226 }
1227 aTimer.Stop();
1228
1229 const Standard_Real aTime2 = aTimer.ElapsedTime();
1230
1231 aTimer.Reset();
1232 aTimer.Start();
1233 for (Standard_Integer anId = 0; anId < aNbItems; ++anId)
1234 {
1235 if (aIndxMap.FindIndex (aItems[anId]) != aIndxs[anId])
1236 {
1237 std::cout << "failed FindIndex\n";
1238 }
1239
1240 if (aIndxMap.FindKey (aIndxs[anId]) != aItems[anId])
1241 {
1242 std::cout << "failed FindKey\n";
1243 }
1244 }
1245 aTimer.Stop();
1246
1247 const Standard_Real aTime3 = aTimer.ElapsedTime();
1248
1249 aTimer.Reset();
1250 aTimer.Start();
1251 for (Standard_Integer anId = 0; anId < aNbItems; ++anId)
1252 {
1253 aIndxMap.RemoveLast();
1254 }
1255 aTimer.Stop();
1256
1257 const Standard_Real aTime4 = aTimer.ElapsedTime();
1258
1259 di << "Search time 1: " << aTime1 << "\n"
1260 << "Swapping time: " << aTime2 << "\n"
1261 << "Search time 2: " << aTime3 << "\n"
1262 << "Remove time: " << aTime4 << "\n";
1263
1264 return 0;
1265}
1266
1267//=======================================================================
1268//function : QANTestNCollectionIndexedDataMap
1269//purpose :
1270//=======================================================================
1271static Standard_Integer QANTestNCollectionIndexedDataMap (Draw_Interpretor& di, Standard_Integer, const char**)
1272{
1273 OSD_Timer aTimer;
1274
1275 std::vector<Standard_Integer> aIndxs;
1276 std::vector<Standard_Integer> aItems;
1277 NCollection_IndexedDataMap<Standard_Integer, Standard_Integer> aIndxMap;
1278
1279 const Standard_Integer aNbItems = 1000000;
1280
1281 srand (1);
1282 for (Standard_Integer anId = 1; anId <= aNbItems; ++anId)
1283 {
1284 const Standard_Integer aVal = anId * 2;
1285
1286 aIndxs.push_back (anId);
1287 aItems.push_back (aVal);
1288
1289 aIndxMap.Add (aVal, aVal * 2);
1290 }
1291
1292 aTimer.Start();
1293 for (Standard_Integer anId = 0; anId < aNbItems; ++anId)
1294 {
1295 if (aIndxMap.FindIndex (aItems[anId]) != aIndxs[anId])
1296 {
1297 std::cout << "failed FindIndex\n";
1298 }
1299
1300 if (aIndxMap.FindKey (aIndxs[anId]) != aItems[anId])
1301 {
1302 std::cout << "failed FindKey\n";
1303 }
1304 }
1305 aTimer.Stop();
1306
1307 const Standard_Real aTime1 = aTimer.ElapsedTime();
1308
1309 aTimer.Reset();
1310 aTimer.Start();
1311 for (Standard_Integer anId = 0; anId < aNbItems / 30; ++anId)
1312 {
1313 const Standard_Integer anId2 = Min (aNbItems - 1,
1314 static_cast<Standard_Integer> (rand() / float (RAND_MAX) * aNbItems));
1315
1316 aIndxMap.Swap (aIndxs[anId], aIndxs[anId2]);
1317
1318 std::swap (aIndxs[anId], aIndxs[anId2]);
1319 }
1320 aTimer.Stop();
1321
1322 const Standard_Real aTime2 = aTimer.ElapsedTime();
1323
1324 aTimer.Reset();
1325 aTimer.Start();
1326 for (Standard_Integer anId = 0; anId < aNbItems; ++anId)
1327 {
1328 if (aIndxMap.FindIndex (aItems[anId]) != aIndxs[anId])
1329 {
1330 std::cout << "failed FindIndex\n";
1331 }
1332
1333 if (aIndxMap.FindKey (aIndxs[anId]) != aItems[anId])
1334 {
1335 std::cout << "failed FindKey\n";
1336 }
1337 }
1338 aTimer.Stop();
1339
1340 const Standard_Real aTime3 = aTimer.ElapsedTime();
1341
1342 aTimer.Reset();
1343 aTimer.Start();
1344 for (Standard_Integer anId = 0; anId < aNbItems; ++anId)
1345 {
1346 aIndxMap.RemoveLast();
1347 }
1348 aTimer.Stop();
1349
1350 const Standard_Real aTime4 = aTimer.ElapsedTime();
1351
1352 di << "Search time 1: " << aTime1 << "\n"
1353 << "Swapping time: " << aTime2 << "\n"
1354 << "Search time 2: " << aTime3 << "\n"
1355 << "Remove time: " << aTime4 << "\n";
1356
79a35943 1357 return 0;
1358}
1359
1360//=======================================================================
1361//function : CommandsStl
1362//purpose :
1363//=======================================================================
1364void QANCollection::CommandsStl (Draw_Interpretor& theCommands)
1365{
1366 const char* aGroup = "QANCollection";
1367
1368 theCommands.Add ("QANArray1StlIterator",
1369 "QANArray1StlIterator",
1370 __FILE__,
1371 QANArray1StlIterator,
1372 aGroup);
1373
1374 theCommands.Add ("QANListStlIterator",
1375 "QANListStlIterator",
1376 __FILE__,
1377 QANListStlIterator,
1378 aGroup);
1379
1380 theCommands.Add ("QANSequenceStlIterator",
1381 "QANSequenceStlIterator",
1382 __FILE__,
1383 QANSequenceStlIterator,
1384 aGroup);
1385
1386 theCommands.Add ("QANVectorStlIterator",
1387 "QANVectorStlIterator",
1388 __FILE__,
1389 QANVectorStlIterator,
1390 aGroup);
1391
1392 theCommands.Add ("QANMapStlIterator",
1393 "QANMapStlIterator",
1394 __FILE__,
1395 QANMapStlIterator,
1396 aGroup);
1397
1398 theCommands.Add ("QANDataMapStlIterator",
1399 "QANDataMapStlIterator",
1400 __FILE__,
1401 QANDataMapStlIterator,
1402 aGroup);
1403
1404 theCommands.Add ("QANIndexedMapStlIterator",
1405 "QANIndexedMapStlIterator",
1406 __FILE__,
1407 QANIndexedMapStlIterator,
1408 aGroup);
1409
1410 theCommands.Add ("QANIndexedDataMapStlIterator",
1411 "QANIndexedDataMapStlIterator",
1412 __FILE__,
1413 QANIndexedDataMapStlIterator,
1414 aGroup);
1415
1416 theCommands.Add ("QANTestStlIterators",
1417 "QANTestStlIterators",
1418 __FILE__,
1419 QANTestStlIterators,
1420 aGroup);
1421
1422 theCommands.Add ("QANTestNCollectionPerformance",
1423 "QANTestNCollectionPerformance",
1424 __FILE__,
1425 QANTestNCollectionPerformance,
1426 aGroup);
1427
9e506120 1428 theCommands.Add ("QANTestNCollectionIndexedMap",
1429 "QANTestNCollectionIndexedMap",
1430 __FILE__,
1431 QANTestNCollectionIndexedMap,
1432 aGroup);
1433
1434 theCommands.Add ("QANTestNCollectionIndexedDataMap",
1435 "QANTestNCollectionIndexedDataMap",
1436 __FILE__,
1437 QANTestNCollectionIndexedDataMap,
1438 aGroup);
1439
79a35943 1440 return;
1441}