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. |
37 | const int THE_TEST_SIZE = 5000; |
38 | |
39 | namespace { |
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 | |
47 | template<class CollectionType, class StlType> |
48 | struct 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 | |
69 | template<class T, typename StlType> |
70 | struct 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 | |
92 | template<class CollectionType, class T> |
93 | struct 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 | |
106 | template<class T> |
107 | struct 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 | |
130 | template<class T> |
131 | struct 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 | //======================================================================= |
158 | template<class CollectionType, class StlType> |
159 | Standard_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 | //======================================================================= |
192 | template<class CollectionType, class StlType> |
193 | Standard_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 | //======================================================================= |
224 | template<class CollectionType, class StlType> |
225 | Standard_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 | //======================================================================= |
263 | template<class CollectionType, class StlType> |
264 | Standard_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 | //======================================================================= |
300 | template<class CollectionType, class StlType> |
301 | Standard_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 |
333 | template <typename T> |
334 | struct Invoker |
335 | { |
336 | void operator()(T& theValue) const |
337 | { |
338 | theValue *= 2; |
339 | } |
340 | }; |
341 | |
342 | //======================================================================= |
c7b59798 |
343 | //function : TestParallel |
79a35943 |
344 | //purpose : |
345 | //======================================================================= |
346 | template<class CollectionType, class StlType> |
c7b59798 |
347 | Standard_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 | //======================================================================= |
383 | template<class CollectionType, class T> |
c7b59798 |
384 | Standard_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 | //======================================================================= |
422 | template<class CollectionType, class T> |
423 | Standard_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 | //======================================================================= |
457 | template <class CollectionType> |
458 | void 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; |
5b111128 |
492 | (void)ct; |
79a35943 |
493 | // *cit2 = ct; |
494 | // *(cit2.operator-> ()) = t; |
495 | |
496 | delete aCollec; |
497 | } |
498 | |
499 | //======================================================================= |
500 | //function : TestBidirIterator |
501 | //purpose : test features of bidirectional iterator |
502 | //======================================================================= |
503 | template <class CollectionType> |
504 | void TestBidirIterator () |
505 | { |
506 | CollectionType* aCollec (NULL); |
507 | |
508 | CollectionFiller<CollectionType, void>::Perform (&aCollec); |
509 | |
510 | // test non-const iteration |
511 | typename CollectionType::iterator it = aCollec->end(); // copy construction |
512 | typename CollectionType::iterator it2 = it--; // postfix decrement |
513 | if (it2 == it || ! (it2 != it)) |
514 | std::cout << "Failed " << typeid(it).name() << " equality check" << std::endl; |
515 | it2 = --it; // prefix decrement |
516 | if (it2 != it || ! (it2 == it)) |
517 | std::cout << "Failed " << typeid(it).name() << " equality check" << std::endl; |
518 | |
519 | delete aCollec; |
520 | } |
521 | |
522 | //======================================================================= |
523 | //function : TestRandomIterator |
524 | //purpose : test features of random iterator |
525 | //======================================================================= |
526 | template <class CollectionType> |
527 | void TestRandomIterator () |
528 | { |
529 | CollectionType* aCollec (NULL); |
530 | |
531 | CollectionFiller<CollectionType, void>::Perform (&aCollec); |
532 | |
533 | // test non-const iteration |
534 | typename CollectionType::iterator it = aCollec->begin(); // copy construction |
535 | typename CollectionType::iterator it2 = it + 5; |
536 | if ((it2 - it) != 5) |
537 | std::cout << "Failed " << typeid(it).name() << " arithmetics" << std::endl; |
538 | if (it2 < it || it2 <= it || ! (it2 > it) || ! (it2 >= it)) |
539 | std::cout << "Failed " << typeid(it).name() << " comparison" << std::endl; |
540 | it += 5; |
541 | if (it2 != it) |
542 | std::cout << "Failed " << typeid(it).name() << " arithmetics" << std::endl; |
543 | it2 = it - 5; |
544 | if ((it2 - it) != -5) |
545 | std::cout << "Failed " << typeid(it).name() << " arithmetics" << std::endl; |
546 | if (it2 > it || it2 >= it || ! (it2 < it) || ! (it2 <= it)) |
547 | std::cout << "Failed " << typeid(it).name() << " comparison" << std::endl; |
548 | it -= 5; |
549 | if (it2 != it) |
550 | std::cout << "Failed " << typeid(it).name() << " arithmetics" << std::endl; |
551 | |
552 | typename CollectionType::value_type t = it[5]; // offset dereference |
553 | *it = t; |
554 | |
555 | delete aCollec; |
556 | } |
557 | |
558 | //======================================================================= |
559 | //function : QANListStlIterator |
560 | //purpose : |
561 | //======================================================================= |
562 | static Standard_Integer QANListStlIterator (Draw_Interpretor&, Standard_Integer, const char**) |
563 | { |
564 | // compile-time tests |
565 | TestForwardIterator <NCollection_List<Standard_Integer> >(); |
566 | |
567 | // run-time tests |
568 | Standard_Boolean aResult = TestIteration<NCollection_List<int>, std::list<int> >(); |
569 | std::cout << "NCollection_List<int> Iteration: " << |
570 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
571 | |
572 | aResult = TestIteration<NCollection_List<double>, std::list<double> >(); |
573 | std::cout << "NCollection_List<double> Iteration: " << |
574 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
575 | |
576 | aResult = TestMinMax<NCollection_List<int>, std::list<int> >(); |
577 | std::cout << "NCollection_List<int> Min-Max: " << |
578 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
579 | |
580 | aResult = TestMinMax<NCollection_List<double>, std::list<double> >(); |
581 | std::cout << "NCollection_List<double> Min-Max: " << |
582 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
583 | |
584 | aResult = TestReplace<NCollection_List<int>, std::list<int> >(); |
585 | std::cout << "NCollection_List<int> Replace: " << |
586 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
587 | |
588 | aResult = TestReplace<NCollection_List<double>, std::list<double> >(); |
589 | std::cout << "NCollection_List<double> Replace: " << |
590 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
591 | |
c7b59798 |
592 | aResult = TestParallel< NCollection_List<int>, std::list<int> >(); |
593 | std::cout << "NCollection_List<int> Parallel: " << |
79a35943 |
594 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
595 | |
c7b59798 |
596 | aResult = TestParallel<NCollection_List<double>, std::list<double> >(); |
597 | std::cout << "NCollection_List<double> Parallel: " << |
79a35943 |
598 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
599 | |
79a35943 |
600 | return 0; |
601 | } |
602 | |
603 | //======================================================================= |
604 | //function : QANMapStlIterator |
605 | //purpose : |
606 | //======================================================================= |
607 | static Standard_Integer QANMapStlIterator (Draw_Interpretor&, Standard_Integer, const char**) |
608 | { |
609 | // compile-time tests |
610 | // TestForwardIterator <NCollection_Map<Standard_Integer> >(); |
611 | |
612 | // run-time tests |
613 | Standard_Boolean aResult = TestMapIteration<NCollection_Map<Standard_Integer>, Standard_Integer>(); |
614 | std::cout << "NCollection_Map<int> Iteration: " << |
615 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
616 | |
617 | aResult = TestMapIteration<NCollection_Map<Standard_Real>, Standard_Real>(); |
618 | std::cout << "NCollection_Map<double> Iteration: " << |
619 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
620 | |
621 | return 0; |
622 | } |
623 | |
624 | //======================================================================= |
625 | //function : QANIndexedMapStlIterator |
626 | //purpose : |
627 | //======================================================================= |
628 | static Standard_Integer QANIndexedMapStlIterator (Draw_Interpretor&, Standard_Integer, const char**) |
629 | { |
630 | // compile-time tests |
631 | // TestForwardIterator <NCollection_IndexedMap<Standard_Integer> >(); |
632 | // TestBidirIterator <NCollection_IndexedMap<Standard_Integer> >(); |
633 | |
634 | // run-time tests |
635 | Standard_Boolean aResult = TestMapIteration<NCollection_IndexedMap<Standard_Integer>, Standard_Integer>(); |
636 | std::cout << "NCollection_IndexedMap<int> Iteration: " << |
637 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
638 | |
639 | aResult = TestMapIteration<NCollection_IndexedMap<Standard_Real>, Standard_Real>(); |
640 | std::cout << "NCollection_IndexedMap<double> Iteration: " << |
641 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
642 | |
643 | return 0; |
644 | } |
645 | |
646 | //======================================================================= |
647 | //function : QANDataMapStlIterator |
648 | //purpose : |
649 | //======================================================================= |
650 | static Standard_Integer QANDataMapStlIterator (Draw_Interpretor&, Standard_Integer, const char**) |
651 | { |
652 | // compile-time tests |
653 | // TestForwardIterator <NCollection_DataMap<int, int> >(); |
654 | // TestBidirIterator <NCollection_DataMap<int, int> >(); |
655 | |
656 | // run-time tests |
657 | Standard_Boolean aResult = TestMapIteration<NCollection_DataMap<Standard_Integer, Standard_Integer>, Standard_Integer>(); |
658 | std::cout << "NCollection_DataMap<int> Iteration: " << |
659 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
660 | |
661 | aResult = TestMapIteration<NCollection_DataMap<Standard_Real, Standard_Real>, Standard_Real>(); |
662 | std::cout << "NCollection_DataMap<double> Iteration: " << |
663 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
664 | |
c7b59798 |
665 | aResult = TestDataMapParallel<NCollection_DataMap<Standard_Integer, Standard_Integer>, Standard_Integer>(); |
666 | std::cout << "NCollection_DataMap<int> Parallel: " << |
79a35943 |
667 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
668 | |
c7b59798 |
669 | aResult = TestDataMapParallel<NCollection_DataMap<Standard_Real, Standard_Real>, Standard_Real>(); |
670 | std::cout << "NCollection_DataMap<double> Parallel: " << |
79a35943 |
671 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
672 | |
79a35943 |
673 | return 0; |
674 | } |
675 | |
676 | //======================================================================= |
677 | //function : QANIndexedDataMapStlIterator |
678 | //purpose : |
679 | //======================================================================= |
680 | static Standard_Integer QANIndexedDataMapStlIterator (Draw_Interpretor&, Standard_Integer, const char**) |
681 | { |
682 | // compile-time tests |
683 | // TestForwardIterator <NCollection_IndexedDataMap<int, int> >(); |
684 | // TestBidirIterator <NCollection_IndexedDataMap<int, int> >(); |
685 | |
686 | // run-time tests |
687 | Standard_Boolean aResult = TestMapIteration<NCollection_IndexedDataMap<Standard_Integer, Standard_Integer>, Standard_Integer>(); |
688 | std::cout << "NCollection_IndexedDataMap<int> Iteration: " << |
689 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
690 | |
691 | aResult = TestMapIteration<NCollection_IndexedDataMap<Standard_Real, Standard_Real>, Standard_Real>(); |
692 | std::cout << "NCollection_IndexedDataMap<double> Iteration: " << |
693 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
694 | |
c7b59798 |
695 | aResult = TestDataMapParallel<NCollection_IndexedDataMap<Standard_Integer, Standard_Integer>, Standard_Integer>(); |
696 | std::cout << "NCollection_IndexedDataMap<int> Parallel: " << |
79a35943 |
697 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
698 | |
c7b59798 |
699 | aResult = TestDataMapParallel<NCollection_IndexedDataMap<Standard_Real, Standard_Real>, Standard_Real>(); |
700 | std::cout << "NCollection_IndexedDataMap<double> Parallel: " << |
79a35943 |
701 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
702 | |
79a35943 |
703 | return 0; |
704 | } |
705 | |
706 | //======================================================================= |
707 | //function : QANSequenceStlIterator |
708 | //purpose : |
709 | //======================================================================= |
710 | static Standard_Integer QANSequenceStlIterator (Draw_Interpretor&, Standard_Integer, const char**) |
711 | { |
712 | // compile-time tests |
713 | TestForwardIterator <NCollection_Sequence<int> >(); |
714 | TestBidirIterator <NCollection_Sequence<int> >(); |
715 | |
716 | // run-time tests |
717 | Standard_Boolean aResult = TestIteration<NCollection_Sequence<int>, std::list<int> >(); |
718 | std::cout << "NCollection_Sequence<int> Iteration: " << |
719 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
720 | |
721 | aResult = TestIteration<NCollection_Sequence<double>, std::list<double> >(); |
722 | std::cout << "NCollection_Sequence<double> Iteration: " << |
723 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
724 | |
725 | aResult = TestMinMax<NCollection_Sequence<int>, std::list<int> >(); |
726 | std::cout << "NCollection_Sequence<int> Min-Max: " << |
727 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
728 | |
729 | aResult = TestMinMax<NCollection_Sequence<double>, std::list<double> >(); |
730 | std::cout << "NCollection_Sequence<double> Min-Max: " << |
731 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
732 | |
733 | aResult = TestReplace<NCollection_Sequence<int>, std::list<int> >(); |
734 | std::cout << "NCollection_Sequence<int> Replace: " << |
735 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
736 | |
737 | aResult = TestReplace<NCollection_Sequence<double>, std::list<double> >(); |
738 | std::cout << "NCollection_Sequence<double> Replace: " << |
739 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
740 | |
741 | aResult = TestReverse<NCollection_Sequence<int>, std::list<int> >(); |
742 | std::cout << "NCollection_Sequence<int> Reverse: " << |
743 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
744 | |
745 | aResult = TestReverse<NCollection_Sequence<double>, std::list<double> >(); |
746 | std::cout << "NCollection_Sequence<double> Reverse: " << |
747 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
748 | |
c7b59798 |
749 | aResult = TestParallel<NCollection_Sequence<int>, std::list<int> >(); |
750 | std::cout << "NCollection_Sequence<int> Parallel: " << |
79a35943 |
751 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
752 | |
c7b59798 |
753 | aResult = TestParallel<NCollection_Sequence<double>, std::list<double> >(); |
754 | std::cout << "NCollection_Sequence<double> Parallel: " << |
79a35943 |
755 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
756 | |
79a35943 |
757 | return 0; |
758 | } |
759 | |
760 | //======================================================================= |
761 | //function : QANVectorStlIterator |
762 | //purpose : |
763 | //======================================================================= |
764 | static Standard_Integer QANVectorStlIterator (Draw_Interpretor&, Standard_Integer, const char**) |
765 | { |
766 | // compile-time tests |
767 | TestForwardIterator <NCollection_Vector<int> >(); |
768 | TestBidirIterator <NCollection_Vector<int> >(); |
769 | TestRandomIterator <NCollection_Vector<int> >(); |
770 | |
771 | // run-time tests |
772 | Standard_Boolean aResult = TestIteration<NCollection_Vector<int>, std::vector<int> >(); |
773 | std::cout << "NCollection_Vector<int> Iteration: " << |
774 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
775 | |
776 | aResult = TestIteration<NCollection_Vector<double>, std::vector<double> >(); |
777 | std::cout << "NCollection_Vector<double> Iteration: " << |
778 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
779 | |
780 | aResult = TestMinMax<NCollection_Vector<int>, std::vector<int> >(); |
781 | std::cout << "NCollection_Vector<int> Min-Max: " << |
782 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
783 | |
784 | aResult = TestMinMax<NCollection_Vector<double>, std::vector<double> >(); |
785 | std::cout << "NCollection_Vector<double> Min-Max: " << |
786 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
787 | |
788 | aResult = TestReplace<NCollection_Vector<int>, std::vector<int> >(); |
789 | std::cout << "NCollection_Vector<int> Replace: " << |
790 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
791 | |
792 | aResult = TestReplace<NCollection_Vector<double>, std::vector<double> >(); |
793 | std::cout << "NCollection_Vector<double> Replace: " << |
794 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
795 | |
796 | aResult = TestReverse<NCollection_Vector<int>, std::vector<int> >(); |
797 | std::cout << "NCollection_Vector<int> Reverse: " << |
798 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
799 | |
800 | aResult = TestReverse<NCollection_Vector<double>, std::vector<double> >(); |
801 | std::cout << "NCollection_Vector<double> Reverse: " << |
802 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
803 | |
804 | aResult = TestSort<NCollection_Vector<int>, std::vector<int> >(); |
805 | std::cout << "NCollection_Vector<int> Sort: " << |
806 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
807 | |
808 | aResult = TestSort<NCollection_Vector<double>, std::vector<double> >(); |
809 | std::cout << "NCollection_Vector<double> Sort: " << |
810 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
811 | |
c7b59798 |
812 | aResult = TestParallel<NCollection_Vector<int>, std::vector<int> >(); |
813 | std::cout << "NCollection_Vector<int> Parallel: " << |
79a35943 |
814 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
815 | |
c7b59798 |
816 | aResult = TestParallel<NCollection_Vector<double>, std::vector<double> >(); |
817 | std::cout << "NCollection_Vector<double> Parallel: " << |
79a35943 |
818 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
819 | |
79a35943 |
820 | return 0; |
821 | } |
822 | |
823 | //======================================================================= |
824 | //function : QANArray1StlIterator |
825 | //purpose : |
826 | //======================================================================= |
827 | static Standard_Integer QANArray1StlIterator (Draw_Interpretor&, Standard_Integer, const char**) |
828 | { |
829 | // compile-time tests |
830 | TestForwardIterator <NCollection_Vector<int> >(); |
831 | TestBidirIterator <NCollection_Vector<int> >(); |
832 | TestRandomIterator <NCollection_Vector<int> >(); |
833 | |
834 | // run-time tests |
835 | Standard_Boolean aResult = TestIteration<NCollection_Array1<int>, std::vector<int> >(); |
836 | std::cout << "NCollection_Array1<int> Iteration: " << |
837 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
838 | |
839 | aResult = TestIteration<NCollection_Array1<double>, std::vector<double> >(); |
840 | std::cout << "NCollection_Array1<double> Iteration: " << |
841 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
842 | |
843 | aResult = TestMinMax<NCollection_Array1<int>, std::vector<int> >(); |
844 | std::cout << "NCollection_Array1<int> Min-Max: " << |
845 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
846 | |
847 | aResult = TestMinMax<NCollection_Array1<double>, std::vector<double> >(); |
848 | std::cout << "NCollection_Array1<double> Min-Max: " << |
849 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
850 | |
851 | aResult = TestReplace<NCollection_Array1<int>, std::vector<int> >(); |
852 | std::cout << "NCollection_Array1<int> Replace: " << |
853 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
854 | |
855 | aResult = TestReplace<NCollection_Array1<double>, std::vector<double> >(); |
856 | std::cout << "NCollection_Array1<double> Replace: " << |
857 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
858 | |
859 | aResult = TestReverse<NCollection_Array1<int>, std::vector<int> >(); |
860 | std::cout << "NCollection_Array1<int> Reverse: " << |
861 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
862 | |
863 | aResult = TestReverse<NCollection_Array1<double>, std::vector<double> >(); |
864 | std::cout << "NCollection_Array1<double> Reverse: " << |
865 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
866 | |
867 | aResult = TestSort<NCollection_Array1<int>, std::vector<int> >(); |
868 | std::cout << "NCollection_Array1<int> Sort: " << |
869 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
870 | |
871 | aResult = TestSort<NCollection_Array1<double>, std::vector<double> >(); |
872 | std::cout << "NCollection_Array1<double> Sort: " << |
873 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
874 | |
c7b59798 |
875 | aResult = TestParallel<NCollection_Array1<int>, std::vector<int> >(); |
876 | std::cout << "NCollection_Array1<int> Parallel: " << |
79a35943 |
877 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
878 | |
c7b59798 |
879 | aResult = TestParallel<NCollection_Array1<double>, std::vector<double> >(); |
880 | std::cout << "NCollection_Array1<double> Parallel: " << |
79a35943 |
881 | (aResult ? "SUCCESS" : "FAIL") << std::endl; |
882 | |
79a35943 |
883 | return 0; |
884 | } |
885 | |
886 | //======================================================================= |
887 | //function : QANTestStlIterators |
888 | //purpose : |
889 | //======================================================================= |
890 | static Standard_Integer QANTestStlIterators ( |
891 | Draw_Interpretor& theInterpretor, Standard_Integer, const char**) |
892 | { |
893 | QANListStlIterator (theInterpretor, 0, NULL); |
894 | QANArray1StlIterator (theInterpretor, 0, NULL); |
895 | QANVectorStlIterator (theInterpretor, 0, NULL); |
896 | QANSequenceStlIterator (theInterpretor, 0, NULL); |
897 | QANMapStlIterator (theInterpretor, 0, NULL); |
898 | QANDataMapStlIterator (theInterpretor, 0, NULL); |
899 | QANIndexedMapStlIterator (theInterpretor, 0, NULL); |
900 | QANIndexedDataMapStlIterator (theInterpretor, 0, NULL); |
901 | |
902 | return 0; |
903 | } |
904 | |
905 | //======================================================================= |
906 | //function : TestPerformanceRandomIterator |
907 | //purpose : |
908 | //======================================================================= |
909 | template<class CollectionType, class StlType> |
618617fe |
910 | void TestPerformanceRandomIterator(Draw_Interpretor& di) |
79a35943 |
911 | { |
912 | OSD_Timer aTimer; |
913 | |
914 | StlType* aVector (NULL); |
915 | CollectionType* aCollec (NULL); |
916 | |
917 | for (Standard_Integer aSize = 10000; aSize <= 1280000; aSize *= 2) |
918 | { |
919 | CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec, aSize); |
920 | |
921 | aTimer.Reset(); |
922 | aTimer.Start(); |
923 | { |
924 | RandomGenerator aRandomGen; |
925 | for (Standard_Integer anIdx = 0; anIdx < 10; ++anIdx) |
926 | { |
927 | std::sort (aVector->begin(), aVector->end()); |
928 | std::random_shuffle (aVector->begin(), aVector->end(), aRandomGen); |
929 | } |
930 | } |
931 | aTimer.Stop(); |
932 | |
933 | Standard_Real aStlTime = aTimer.ElapsedTime(); |
934 | |
935 | aTimer.Reset(); |
936 | aTimer.Start(); |
937 | { |
938 | RandomGenerator aRandomGen; |
939 | for (Standard_Integer anIdx = 0; anIdx < 10; ++anIdx) |
940 | { |
941 | std::sort (aCollec->begin(), aCollec->end()); |
942 | std::random_shuffle (aCollec->begin(), aCollec->end(), aRandomGen); |
943 | } |
944 | } |
945 | aTimer.Stop(); |
946 | |
947 | Standard_Real aOccTime = aTimer.ElapsedTime(); |
948 | |
618617fe |
949 | di << aSize << "\t" << aStlTime << "\t" << |
950 | aOccTime << "\t" << aOccTime / aStlTime << "\n"; |
79a35943 |
951 | |
952 | // check that result is the same |
953 | if ( ! std::equal (aVector->begin(), aVector->end(), aCollec->begin()) ) |
586db386 |
954 | di << "Error: sequences are not the same at the end!\n"; |
79a35943 |
955 | |
956 | delete aVector; |
957 | delete aCollec; |
958 | } |
959 | } |
960 | |
961 | //======================================================================= |
962 | //function : TestPerformanceForwardIterator |
963 | //purpose : |
964 | //======================================================================= |
965 | template<class CollectionType, class StlType> |
618617fe |
966 | void TestPerformanceForwardIterator(Draw_Interpretor& di) |
79a35943 |
967 | { |
968 | OSD_Timer aTimer; |
969 | |
970 | StlType* aVector = 0; |
971 | CollectionType* aCollec = 0; |
972 | |
973 | for (Standard_Integer aSize = 10000; aSize <= 1280000; aSize *= 2) |
974 | { |
975 | CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec, aSize); |
976 | |
977 | aTimer.Reset(); |
978 | aTimer.Start(); |
979 | { |
980 | for (Standard_Integer anIdx = 0; anIdx < 1000; ++anIdx) |
981 | { |
982 | std::replace (aVector->begin(), aVector->end(), *aVector->begin(), static_cast<typename StlType::value_type> (anIdx)); |
983 | } |
984 | } |
985 | aTimer.Stop(); |
986 | |
987 | Standard_Real aStlTime = aTimer.ElapsedTime(); |
988 | |
989 | aTimer.Reset(); |
990 | aTimer.Start(); |
991 | { |
992 | for (Standard_Integer anIdx = 0; anIdx < 1000; ++anIdx) |
993 | { |
994 | std::replace (aCollec->begin(), aCollec->end(), *aCollec->begin(), static_cast<typename CollectionType::value_type> (anIdx)); |
995 | } |
996 | } |
997 | aTimer.Stop(); |
998 | |
999 | Standard_Real aOccTime = aTimer.ElapsedTime(); |
1000 | |
618617fe |
1001 | di << aSize << "\t" << aStlTime << "\t" << |
1002 | aOccTime << "\t" << aOccTime / aStlTime << "\n"; |
79a35943 |
1003 | |
1004 | // check that result is the same |
1005 | if ( ! std::equal (aVector->begin(), aVector->end(), aCollec->begin()) ) |
586db386 |
1006 | di << "Error: sequences are not the same at the end!\n"; |
79a35943 |
1007 | |
1008 | delete aVector; |
1009 | delete aCollec; |
1010 | } |
1011 | } |
1012 | |
1013 | //======================================================================= |
1014 | //function : TestPerformanceBidirIterator |
1015 | //purpose : |
1016 | //======================================================================= |
1017 | template<class CollectionType, class StlType> |
618617fe |
1018 | void TestPerformanceBidirIterator(Draw_Interpretor& di) |
79a35943 |
1019 | { |
1020 | OSD_Timer aTimer; |
1021 | |
1022 | StlType* aVector = 0; |
1023 | CollectionType* aCollec = 0; |
1024 | |
1025 | for (Standard_Integer aSize = 10000; aSize <= 1280000; aSize *= 2) |
1026 | { |
1027 | CollectionFiller<CollectionType, StlType>::Perform (&aVector, &aCollec, aSize); |
1028 | |
1029 | aTimer.Reset(); |
1030 | aTimer.Start(); |
1031 | { |
1032 | for (Standard_Integer anIdx = 0; anIdx < 1000; ++anIdx) |
1033 | { |
1034 | std::reverse (aVector->begin(), aVector->end()); |
1035 | } |
1036 | } |
1037 | aTimer.Stop(); |
1038 | |
1039 | Standard_Real aStlTime = aTimer.ElapsedTime(); |
1040 | |
1041 | aTimer.Reset(); |
1042 | aTimer.Start(); |
1043 | { |
1044 | for (Standard_Integer anIdx = 0; anIdx < 1000; ++anIdx) |
1045 | { |
1046 | std::reverse (aCollec->begin(), aCollec->end()); |
1047 | } |
1048 | } |
1049 | aTimer.Stop(); |
1050 | |
1051 | Standard_Real aOccTime = aTimer.ElapsedTime(); |
1052 | |
618617fe |
1053 | di << aSize << "\t" << aStlTime << "\t" << |
1054 | aOccTime << "\t" << aOccTime / aStlTime << "\n"; |
79a35943 |
1055 | |
1056 | // check that result is the same |
1057 | if ( ! std::equal (aVector->begin(), aVector->end(), aCollec->begin()) ) |
586db386 |
1058 | di << "Error: sequences are not the same at the end!\n"; |
79a35943 |
1059 | |
1060 | delete aVector; |
1061 | delete aCollec; |
1062 | } |
1063 | } |
1064 | |
1065 | //======================================================================= |
1066 | //function : TestPerformanceMapAccess |
1067 | //purpose : |
1068 | //======================================================================= |
1069 | template<class CollectionType, class T> |
618617fe |
1070 | void TestPerformanceMapAccess(Draw_Interpretor& di) |
79a35943 |
1071 | { |
1072 | OSD_Timer aTimer; |
1073 | |
1074 | CollectionType* aCollec (NULL); |
1075 | |
1076 | for (Standard_Integer aSize = 100000; aSize <= 3200000; aSize *= 2) |
1077 | { |
1078 | MapFiller<CollectionType, T>::Perform (&aCollec, aSize); |
1079 | |
1080 | std::set<T> aSet (aCollec->cbegin(), aCollec->cend()); |
1081 | std::vector<T> aVec (aCollec->cbegin(), aCollec->cend()); |
1082 | |
1083 | Standard_Boolean aResult = Standard_True; |
1084 | |
1085 | aTimer.Reset(); |
1086 | aTimer.Start(); |
1087 | { |
1088 | for (Standard_Integer anIdx = 0; anIdx < 10000; ++anIdx) |
1089 | { |
1090 | if (aSet.find (aVec[anIdx + 1000]) == aSet.end()) |
1091 | aResult = Standard_False; |
1092 | if (aSet.find (aVec[anIdx + 2000]) == aSet.end()) |
1093 | aResult = Standard_False; |
1094 | if (aSet.find (aVec[anIdx + 3000]) == aSet.end()) |
1095 | aResult = Standard_False; |
1096 | if (aSet.find (aVec[anIdx + 4000]) == aSet.end()) |
1097 | aResult = Standard_False; |
1098 | if (aSet.find (aVec[anIdx + 5000]) == aSet.end()) |
1099 | aResult = Standard_False; |
1100 | } |
1101 | } |
1102 | aTimer.Stop(); |
1103 | |
1104 | Standard_Real aStlTime = aTimer.ElapsedTime(); |
1105 | |
1106 | aTimer.Reset(); |
1107 | aTimer.Start(); |
1108 | { |
1109 | for (Standard_Integer anIdx = 0; anIdx < 10000; ++anIdx) |
1110 | { |
1111 | if (!aCollec->Contains (aVec[anIdx + 1000])) |
1112 | aResult = Standard_False; |
1113 | if (!aCollec->Contains (aVec[anIdx + 2000])) |
1114 | aResult = Standard_False; |
1115 | if (!aCollec->Contains (aVec[anIdx + 3000])) |
1116 | aResult = Standard_False; |
1117 | if (!aCollec->Contains (aVec[anIdx + 4000])) |
1118 | aResult = Standard_False; |
1119 | if (!aCollec->Contains (aVec[anIdx + 5000])) |
1120 | aResult = Standard_False; |
1121 | } |
1122 | } |
1123 | aTimer.Stop(); |
1124 | |
1125 | Standard_Real aOccTime = aTimer.ElapsedTime(); |
1126 | |
1127 | if (aResult) |
1128 | { |
618617fe |
1129 | di << aSize << "\t" << aStlTime << "\t" << |
1130 | aOccTime << "\t" << (aStlTime > 1e-16 ? aOccTime / aStlTime : -1) << "\n"; |
79a35943 |
1131 | } |
1132 | |
1133 | delete aCollec; |
1134 | } |
1135 | } |
1136 | |
1137 | //======================================================================= |
1138 | //function : QANTestNCollectionPerformance |
1139 | //purpose : |
1140 | //======================================================================= |
618617fe |
1141 | static Standard_Integer QANTestNCollectionPerformance (Draw_Interpretor& di, Standard_Integer, const char**) |
79a35943 |
1142 | { |
586db386 |
1143 | di << "Testing performance (Size | STL time | OCCT time | STL/OCCT boost)\n"; |
79a35943 |
1144 | |
586db386 |
1145 | di << "\nstd::vector vs NCollection_Array1 (sort):\n\n"; |
618617fe |
1146 | TestPerformanceRandomIterator<NCollection_Array1<double>, std::vector<double> >(di); |
9e506120 |
1147 | |
586db386 |
1148 | di << "\nstd::vector vs NCollection_Vector (sort):\n\n"; |
618617fe |
1149 | TestPerformanceRandomIterator<NCollection_Vector<double>, std::vector<double> >(di); |
9e506120 |
1150 | |
586db386 |
1151 | di << "\nstd::vector vs NCollection_Array1 (replace):\n\n"; |
618617fe |
1152 | TestPerformanceForwardIterator<NCollection_Array1<double>, std::vector<double> >(di); |
9e506120 |
1153 | |
586db386 |
1154 | di << "\nstd::vector vs NCollection_Vector (replace):\n\n"; |
618617fe |
1155 | TestPerformanceForwardIterator<NCollection_Vector<double>, std::vector<double> >(di); |
79a35943 |
1156 | |
586db386 |
1157 | di << "\nstd::list vs NCollection_List (replace):\n\n"; |
618617fe |
1158 | TestPerformanceForwardIterator<NCollection_List<double>, std::list<double> >(di); |
79a35943 |
1159 | |
586db386 |
1160 | di << "\nstd::list vs NCollection_Sequence (replace):\n\n"; |
618617fe |
1161 | TestPerformanceForwardIterator<NCollection_Sequence<double>, std::list<double> >(di); |
79a35943 |
1162 | |
586db386 |
1163 | di << "\nstd::list vs NCollection_Sequence (reverse):\n\n"; |
618617fe |
1164 | TestPerformanceBidirIterator<NCollection_Sequence<double>, std::list<double> >(di); |
79a35943 |
1165 | |
586db386 |
1166 | di << "\nstd::set vs NCollection_Map (search):\n\n"; |
618617fe |
1167 | TestPerformanceMapAccess<NCollection_Map<int>, int>(di); |
79a35943 |
1168 | |
586db386 |
1169 | di << "\nstd::set vs NCollection_IndexedMap (search):\n\n"; |
618617fe |
1170 | TestPerformanceMapAccess<NCollection_IndexedMap<int>, int>(di); |
9e506120 |
1171 | |
1172 | return 0; |
1173 | } |
1174 | |
1175 | //======================================================================= |
1176 | //function : QANTestNCollectionIndexedMap |
1177 | //purpose : |
1178 | //======================================================================= |
1179 | static Standard_Integer QANTestNCollectionIndexedMap (Draw_Interpretor& di, Standard_Integer, const char**) |
1180 | { |
1181 | OSD_Timer aTimer; |
1182 | |
1183 | std::vector<Standard_Integer> aIndxs; |
1184 | std::vector<Standard_Integer> aItems; |
1185 | NCollection_IndexedMap<Standard_Integer> aIndxMap; |
1186 | |
1187 | const Standard_Integer aNbItems = 1000000; |
1188 | |
1189 | srand (1); |
1190 | for (Standard_Integer anId = 1; anId <= aNbItems; ++anId) |
1191 | { |
1192 | const Standard_Integer aVal = anId * 2; |
1193 | |
1194 | aIndxs.push_back (anId); |
1195 | aItems.push_back (aVal); |
1196 | |
1197 | aIndxMap.Add (aVal); |
1198 | } |
1199 | |
1200 | aTimer.Start(); |
1201 | for (Standard_Integer anId = 0; anId < aNbItems; ++anId) |
1202 | { |
1203 | if (aIndxMap.FindIndex (aItems[anId]) != aIndxs[anId]) |
1204 | { |
1205 | std::cout << "failed FindIndex\n"; |
1206 | } |
1207 | |
1208 | if (aIndxMap.FindKey (aIndxs[anId]) != aItems[anId]) |
1209 | { |
1210 | std::cout << "failed FindKey\n"; |
1211 | } |
1212 | } |
1213 | aTimer.Stop(); |
1214 | |
1215 | const Standard_Real aTime1 = aTimer.ElapsedTime(); |
1216 | |
1217 | aTimer.Reset(); |
1218 | aTimer.Start(); |
1219 | for (Standard_Integer anId = 0; anId < aNbItems / 30; ++anId) |
1220 | { |
1221 | const Standard_Integer anId2 = Min (aNbItems - 1, |
1222 | static_cast<Standard_Integer> (rand() / float (RAND_MAX) * aNbItems)); |
1223 | |
1224 | aIndxMap.Swap (aIndxs[anId], aIndxs[anId2]); |
1225 | |
1226 | std::swap (aIndxs[anId], aIndxs[anId2]); |
1227 | } |
1228 | aTimer.Stop(); |
1229 | |
1230 | const Standard_Real aTime2 = aTimer.ElapsedTime(); |
1231 | |
1232 | aTimer.Reset(); |
1233 | aTimer.Start(); |
1234 | for (Standard_Integer anId = 0; anId < aNbItems; ++anId) |
1235 | { |
1236 | if (aIndxMap.FindIndex (aItems[anId]) != aIndxs[anId]) |
1237 | { |
1238 | std::cout << "failed FindIndex\n"; |
1239 | } |
1240 | |
1241 | if (aIndxMap.FindKey (aIndxs[anId]) != aItems[anId]) |
1242 | { |
1243 | std::cout << "failed FindKey\n"; |
1244 | } |
1245 | } |
1246 | aTimer.Stop(); |
1247 | |
1248 | const Standard_Real aTime3 = aTimer.ElapsedTime(); |
1249 | |
1250 | aTimer.Reset(); |
1251 | aTimer.Start(); |
1252 | for (Standard_Integer anId = 0; anId < aNbItems; ++anId) |
1253 | { |
1254 | aIndxMap.RemoveLast(); |
1255 | } |
1256 | aTimer.Stop(); |
1257 | |
1258 | const Standard_Real aTime4 = aTimer.ElapsedTime(); |
1259 | |
1260 | di << "Search time 1: " << aTime1 << "\n" |
1261 | << "Swapping time: " << aTime2 << "\n" |
1262 | << "Search time 2: " << aTime3 << "\n" |
1263 | << "Remove time: " << aTime4 << "\n"; |
1264 | |
1265 | return 0; |
1266 | } |
1267 | |
1268 | //======================================================================= |
1269 | //function : QANTestNCollectionIndexedDataMap |
1270 | //purpose : |
1271 | //======================================================================= |
1272 | static Standard_Integer QANTestNCollectionIndexedDataMap (Draw_Interpretor& di, Standard_Integer, const char**) |
1273 | { |
1274 | OSD_Timer aTimer; |
1275 | |
1276 | std::vector<Standard_Integer> aIndxs; |
1277 | std::vector<Standard_Integer> aItems; |
1278 | NCollection_IndexedDataMap<Standard_Integer, Standard_Integer> aIndxMap; |
1279 | |
1280 | const Standard_Integer aNbItems = 1000000; |
1281 | |
1282 | srand (1); |
1283 | for (Standard_Integer anId = 1; anId <= aNbItems; ++anId) |
1284 | { |
1285 | const Standard_Integer aVal = anId * 2; |
1286 | |
1287 | aIndxs.push_back (anId); |
1288 | aItems.push_back (aVal); |
1289 | |
1290 | aIndxMap.Add (aVal, aVal * 2); |
1291 | } |
1292 | |
1293 | aTimer.Start(); |
1294 | for (Standard_Integer anId = 0; anId < aNbItems; ++anId) |
1295 | { |
1296 | if (aIndxMap.FindIndex (aItems[anId]) != aIndxs[anId]) |
1297 | { |
1298 | std::cout << "failed FindIndex\n"; |
1299 | } |
1300 | |
1301 | if (aIndxMap.FindKey (aIndxs[anId]) != aItems[anId]) |
1302 | { |
1303 | std::cout << "failed FindKey\n"; |
1304 | } |
1305 | } |
1306 | aTimer.Stop(); |
1307 | |
1308 | const Standard_Real aTime1 = aTimer.ElapsedTime(); |
1309 | |
1310 | aTimer.Reset(); |
1311 | aTimer.Start(); |
1312 | for (Standard_Integer anId = 0; anId < aNbItems / 30; ++anId) |
1313 | { |
1314 | const Standard_Integer anId2 = Min (aNbItems - 1, |
1315 | static_cast<Standard_Integer> (rand() / float (RAND_MAX) * aNbItems)); |
1316 | |
1317 | aIndxMap.Swap (aIndxs[anId], aIndxs[anId2]); |
1318 | |
1319 | std::swap (aIndxs[anId], aIndxs[anId2]); |
1320 | } |
1321 | aTimer.Stop(); |
1322 | |
1323 | const Standard_Real aTime2 = aTimer.ElapsedTime(); |
1324 | |
1325 | aTimer.Reset(); |
1326 | aTimer.Start(); |
1327 | for (Standard_Integer anId = 0; anId < aNbItems; ++anId) |
1328 | { |
1329 | if (aIndxMap.FindIndex (aItems[anId]) != aIndxs[anId]) |
1330 | { |
1331 | std::cout << "failed FindIndex\n"; |
1332 | } |
1333 | |
1334 | if (aIndxMap.FindKey (aIndxs[anId]) != aItems[anId]) |
1335 | { |
1336 | std::cout << "failed FindKey\n"; |
1337 | } |
1338 | } |
1339 | aTimer.Stop(); |
1340 | |
1341 | const Standard_Real aTime3 = aTimer.ElapsedTime(); |
1342 | |
1343 | aTimer.Reset(); |
1344 | aTimer.Start(); |
1345 | for (Standard_Integer anId = 0; anId < aNbItems; ++anId) |
1346 | { |
1347 | aIndxMap.RemoveLast(); |
1348 | } |
1349 | aTimer.Stop(); |
1350 | |
1351 | const Standard_Real aTime4 = aTimer.ElapsedTime(); |
1352 | |
1353 | di << "Search time 1: " << aTime1 << "\n" |
1354 | << "Swapping time: " << aTime2 << "\n" |
1355 | << "Search time 2: " << aTime3 << "\n" |
1356 | << "Remove time: " << aTime4 << "\n"; |
1357 | |
79a35943 |
1358 | return 0; |
1359 | } |
1360 | |
1361 | //======================================================================= |
1362 | //function : CommandsStl |
1363 | //purpose : |
1364 | //======================================================================= |
1365 | void QANCollection::CommandsStl (Draw_Interpretor& theCommands) |
1366 | { |
1367 | const char* aGroup = "QANCollection"; |
1368 | |
1369 | theCommands.Add ("QANArray1StlIterator", |
1370 | "QANArray1StlIterator", |
1371 | __FILE__, |
1372 | QANArray1StlIterator, |
1373 | aGroup); |
1374 | |
1375 | theCommands.Add ("QANListStlIterator", |
1376 | "QANListStlIterator", |
1377 | __FILE__, |
1378 | QANListStlIterator, |
1379 | aGroup); |
1380 | |
1381 | theCommands.Add ("QANSequenceStlIterator", |
1382 | "QANSequenceStlIterator", |
1383 | __FILE__, |
1384 | QANSequenceStlIterator, |
1385 | aGroup); |
1386 | |
1387 | theCommands.Add ("QANVectorStlIterator", |
1388 | "QANVectorStlIterator", |
1389 | __FILE__, |
1390 | QANVectorStlIterator, |
1391 | aGroup); |
1392 | |
1393 | theCommands.Add ("QANMapStlIterator", |
1394 | "QANMapStlIterator", |
1395 | __FILE__, |
1396 | QANMapStlIterator, |
1397 | aGroup); |
1398 | |
1399 | theCommands.Add ("QANDataMapStlIterator", |
1400 | "QANDataMapStlIterator", |
1401 | __FILE__, |
1402 | QANDataMapStlIterator, |
1403 | aGroup); |
1404 | |
1405 | theCommands.Add ("QANIndexedMapStlIterator", |
1406 | "QANIndexedMapStlIterator", |
1407 | __FILE__, |
1408 | QANIndexedMapStlIterator, |
1409 | aGroup); |
1410 | |
1411 | theCommands.Add ("QANIndexedDataMapStlIterator", |
1412 | "QANIndexedDataMapStlIterator", |
1413 | __FILE__, |
1414 | QANIndexedDataMapStlIterator, |
1415 | aGroup); |
1416 | |
1417 | theCommands.Add ("QANTestStlIterators", |
1418 | "QANTestStlIterators", |
1419 | __FILE__, |
1420 | QANTestStlIterators, |
1421 | aGroup); |
1422 | |
1423 | theCommands.Add ("QANTestNCollectionPerformance", |
1424 | "QANTestNCollectionPerformance", |
1425 | __FILE__, |
1426 | QANTestNCollectionPerformance, |
1427 | aGroup); |
1428 | |
9e506120 |
1429 | theCommands.Add ("QANTestNCollectionIndexedMap", |
1430 | "QANTestNCollectionIndexedMap", |
1431 | __FILE__, |
1432 | QANTestNCollectionIndexedMap, |
1433 | aGroup); |
1434 | |
1435 | theCommands.Add ("QANTestNCollectionIndexedDataMap", |
1436 | "QANTestNCollectionIndexedDataMap", |
1437 | __FILE__, |
1438 | QANTestNCollectionIndexedDataMap, |
1439 | aGroup); |
1440 | |
79a35943 |
1441 | return; |
1442 | } |