0024624: Lost word in license statement in source files
[occt.git] / src / QANCollection / QANCollection_PerfMaps.hxx
1 // Created on: 2002-04-30
2 // Created by: Alexander KARTOMIN (akm)
3 // Copyright (c) 2002-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 #ifndef QANCollection_PerfMaps_HeaderFile
17 #define QANCollection_PerfMaps_HeaderFile
18
19 #include <TColStd_MapOfReal.hxx>
20 #include <TColStd_IndexedMapOfReal.hxx>
21 #include <QANCollection_DataMapOfRealPnt.hxx>
22 #include <QANCollection_DoubleMapOfRealInteger.hxx>
23 #include <QANCollection_IndexedDataMapOfRealPnt.hxx>
24
25 // ===================== Test perform of Map type ==========================
26 void CompMap (const Standard_Integer theRep,
27               const Standard_Integer theSize)
28 {
29   Standard_Integer i,j;
30
31   ////////////////////////////////Perf_Meter aNBind ("NCollection_Map adding",0);
32   ////////////////////////////////Perf_Meter aTBind ("TCollection_Map adding",0);
33   ////////////////////////////////Perf_Meter aNOper ("NCollection_Map operator=",0);
34   ////////////////////////////////Perf_Meter aTOper ("TCollection_Map operator=",0);
35   ////////////////////////////////Perf_Meter aNFind ("NCollection_Map finding",0);
36   ////////////////////////////////Perf_Meter aTFind ("TCollection_Map finding",0);
37   ////////////////////////////////Perf_Meter aNClea ("NCollection_Map clearing",0);
38   ////////////////////////////////Perf_Meter aTClea ("TCollection_Map clearing",0);
39   ////////////////////////////////Perf_Meter aNAssi ("NCollection_Map Assign",0);
40   for (i=0; i<theRep; i++)
41     {
42       ////////////////////////////////QANCollection_Map a1, a2;
43       QANCollection_MapPerf a1, a2;
44       ////////////////////////////////aNBind.Start();
45       PERF_START_METER("NCollection_Map adding")
46       for (j=1; j<=theSize; j++)
47         {
48           Key1Type aKey1;
49           Random(aKey1);
50           a1.Add(aKey1);
51         }
52       ////////////////////////////////aNBind.Stop();
53       PERF_STOP_METER("NCollection_Map adding")
54       ////////////////////////////////aNFind.Start();
55       PERF_START_METER("NCollection_Map finding")
56       for (j=1; j<=theSize; j++)
57         {
58           Key1Type aKey1;
59           Random(aKey1);
60           a1.Contains(aKey1);
61         }
62       ////////////////////////////////aNFind.Stop();
63       PERF_STOP_METER("NCollection_Map finding")
64       ////////////////////////////////aNOper.Start();
65       PERF_START_METER("NCollection_Map operator=")
66       a2 = a1;
67       ////////////////////////////////aNOper.Stop();
68       PERF_STOP_METER("NCollection_Map operator=")
69       ////////////////////////////////aNAssi.Start();
70       PERF_START_METER("NCollection_Map Assign")
71       a2.Assign(a1);
72       ////////////////////////////////aNAssi.Stop();
73       PERF_STOP_METER("NCollection_Map Assign")
74       ////////////////////////////////aNClea.Start();
75       PERF_START_METER("NCollection_Map clearing")
76       a2.Clear();
77       ////////////////////////////////aNClea.Stop();
78       PERF_STOP_METER("NCollection_Map clearing")
79     }
80
81   for (i=0; i<theRep; i++)
82     {
83       TColStd_MapOfReal a1, a2;
84       ////////////////////////////////aTBind.Start();
85       PERF_START_METER("TCollection_Map adding")
86       for (j=1; j<=theSize; j++)
87         {
88           Key1Type aKey1;
89           Random(aKey1);
90           a1.Add(aKey1);
91         }
92       ////////////////////////////////aTBind.Stop();
93       PERF_STOP_METER("TCollection_Map adding")
94       ////////////////////////////////aTFind.Start();
95       PERF_START_METER("TCollection_Map finding")
96       for (j=1; j<=theSize; j++)
97         {
98           Key1Type aKey1;
99           Random(aKey1);
100           a1.Contains(aKey1);
101         }
102       ////////////////////////////////aTFind.Stop();
103       PERF_STOP_METER("TCollection_Map finding")
104       ////////////////////////////////aTOper.Start();
105       PERF_START_METER("TCollection_Map operator=")
106       a2 = a1;
107       ////////////////////////////////aTOper.Stop();
108       PERF_STOP_METER("TCollection_Map operator=")
109       ////////////////////////////////aTClea.Start();
110       PERF_START_METER("TCollection_Map clearing")
111       a2.Clear();
112       ////////////////////////////////aTClea.Stop();
113       PERF_STOP_METER("TCollection_Map clearing")
114     }
115   PERF_PRINT_ALL
116 }
117
118 // ===================== Test perform of DataMap type ==========================
119 void CompDataMap (const Standard_Integer theRep,
120                   const Standard_Integer theSize)
121 {
122   Standard_Integer i,j;
123
124   ////////////////////////////////Perf_Meter aNBind ("NCollection_DataMap binding",0);
125   ////////////////////////////////Perf_Meter aTBind ("TCollection_DataMap binding",0);
126   ////////////////////////////////Perf_Meter aNFind ("NCollection_DataMap finding",0);
127   ////////////////////////////////Perf_Meter aTFind ("TCollection_DataMap finding",0);
128   ////////////////////////////////Perf_Meter aNOper ("NCollection_DataMap operator=",0);
129   ////////////////////////////////Perf_Meter aTOper ("TCollection_DataMap operator=",0);
130   ////////////////////////////////Perf_Meter aNClea ("NCollection_DataMap clearing",0);
131   ////////////////////////////////Perf_Meter aTClea ("TCollection_DataMap clearing",0);
132   //////////////////////////////////Perf_Meter aNAssi ("NCollection_DataMap Assign",0);
133   for (i=0; i<theRep; i++)
134     {
135       ////////////////////////////////QANCollection_DataMap a1, a2;
136       QANCollection_DataMapPerf a1, a2;
137       ////////////////////////////////aNBind.Start();
138       PERF_START_METER("NCollection_DataMap binding")
139       for (j=1; j<=theSize; j++)
140         {
141           Key1Type aKey1;
142           ItemType anItem;
143           Random(aKey1);
144           Random(anItem);
145           a1.Bind(aKey1,anItem);
146         }
147       ////////////////////////////////aNBind.Stop();
148       PERF_STOP_METER("NCollection_DataMap binding")
149       ////////////////////////////////aNFind.Start();
150       PERF_START_METER("NCollection_DataMap finding")
151       for (j=1; j<=theSize; j++)
152         {
153           Key1Type aKey1;
154           Random(aKey1);
155           a1.IsBound(aKey1);
156         }
157       ////////////////////////////////aNFind.Stop();
158       PERF_STOP_METER("NCollection_DataMap finding")
159       ////////////////////////////////aNOper.Start();
160       PERF_START_METER("NCollection_DataMap operator=")
161       a2 = a1;
162       ////////////////////////////////aNOper.Stop();
163       PERF_STOP_METER("NCollection_DataMap operator=")
164       //aNAssi.Start();
165       //a2.Assign(a1);
166       //aNAssi.Stop();
167       ////////////////////////////////aNClea.Start();
168       PERF_START_METER("NCollection_DataMap clearing")
169       a2.Clear();
170       ////////////////////////////////aNClea.Stop();
171       PERF_STOP_METER("NCollection_DataMap clearing")
172     }
173
174   for (i=0; i<theRep; i++)
175     {
176       QANCollection_DataMapOfRealPnt a1, a2;
177       ////////////////////////////////aTBind.Start();
178       PERF_START_METER("TCollection_DataMap binding")
179       for (j=1; j<=theSize; j++)
180         {
181           Key1Type aKey1;
182           ItemType anItem;
183           Random(aKey1);
184           Random(anItem);
185           a1.Bind(aKey1,anItem);
186         }
187       ////////////////////////////////aTBind.Stop();
188       PERF_STOP_METER("TCollection_DataMap binding")
189       ////////////////////////////////aTFind.Start();
190       PERF_START_METER("TCollection_DataMap finding")
191       for (j=1; j<=theSize; j++)
192         {
193           Key1Type aKey1;
194           Random(aKey1);
195           a1.IsBound(aKey1);
196         }
197       ////////////////////////////////aTFind.Stop();
198       PERF_STOP_METER("TCollection_DataMap finding")
199       ////////////////////////////////aTOper.Start();
200       PERF_START_METER("TCollection_DataMap operator=")
201       a2 = a1;
202       ////////////////////////////////aTOper.Stop();
203       PERF_STOP_METER("TCollection_DataMap operator=")
204       ////////////////////////////////aTClea.Start();
205       PERF_START_METER("TCollection_DataMap clearing")
206       a2.Clear();
207       ////////////////////////////////aTClea.Stop();
208       PERF_STOP_METER("TCollection_DataMap clearing")
209     }
210   PERF_PRINT_ALL
211 }
212
213 // ===================== Test perform of DoubleMap type ==========================
214 void CompDoubleMap (const Standard_Integer theRep,
215                     const Standard_Integer theSize)
216 {
217   Standard_Integer i,j;
218   Standard_Integer iFail1=0, iFail2=0;
219
220   ////////////////////////////////Perf_Meter aNBind ("NCollection_DoubleMap binding",0);
221   ////////////////////////////////Perf_Meter aTBind ("TCollection_DoubleMap binding",0);
222   ////////////////////////////////Perf_Meter aNFind ("NCollection_DoubleMap finding",0);
223   ////////////////////////////////Perf_Meter aTFind ("TCollection_DoubleMap finding",0);
224   ////////////////////////////////Perf_Meter aNOper ("NCollection_DoubleMap operator=",0);
225   ////////////////////////////////Perf_Meter aTOper ("TCollection_DoubleMap operator=",0);
226   ////////////////////////////////Perf_Meter aNClea ("NCollection_DoubleMap clearing",0);
227   ////////////////////////////////Perf_Meter aTClea ("TCollection_DoubleMap clearing",0);
228   //////////////////////////////////Perf_Meter aNAssi ("NCollection_DoubleMap Assign",0);
229   for (i=0; i<theRep; i++)
230     {
231       ////////////////////////////////QANCollection_DoubleMap a1, a2;
232       QANCollection_DoubleMapPerf a1, a2;
233       ////////////////////////////////aNBind.Start();
234       PERF_START_METER("NCollection_DoubleMap binding")
235       for (j=1; j<=theSize; j++)
236         {
237           Key1Type aKey1;
238           Key2Type aKey2;
239           do {
240             Random(aKey1);
241             Random(aKey2);
242             iFail1++;
243           }
244           while (a1.IsBound1(aKey1) || a1.IsBound2(aKey2));
245           iFail1--;
246           a1.Bind(aKey1,aKey2);
247         }
248       ////////////////////////////////aNBind.Stop();
249       PERF_STOP_METER("NCollection_DoubleMap binding")
250       ////////////////////////////////aNFind.Start();
251       PERF_START_METER("NCollection_DoubleMap finding")
252       for (j=1; j<=theSize; j++)
253         {
254           Key1Type aKey1;
255           Key2Type aKey2;
256           Random(aKey1);
257           Random(aKey2);
258           a1.AreBound(aKey1,aKey2);
259         }
260       ////////////////////////////////aNFind.Stop();
261       PERF_STOP_METER("NCollection_DoubleMap finding")
262       ////////////////////////////////aNOper.Start();
263       PERF_START_METER("NCollection_DoubleMap operator=")
264       a2 = a1;
265       ////////////////////////////////aNOper.Stop();
266       PERF_STOP_METER("NCollection_DoubleMap operator=")
267       //aNAssi.Start();
268       //a2.Assign(a1);
269       //aNAssi.Stop();
270       ////////////////////////////////aNClea.Start();
271       PERF_START_METER("NCollection_DoubleMap clearing")
272       a2.Clear();
273       ////////////////////////////////aNClea.Stop();
274       PERF_STOP_METER("NCollection_DoubleMap clearing")
275     }
276
277   for (i=0; i<theRep; i++)
278     {
279       QANCollection_DoubleMapOfRealInteger a1, a2;
280       ////////////////////////////////aTBind.Start();
281       PERF_START_METER("TCollection_DoubleMap binding")
282       for (j=1; j<=theSize; j++)
283         {
284           Key1Type aKey1;
285           Key2Type aKey2;
286           do {
287             Random(aKey1);
288             Random(aKey2);
289             iFail2++;
290           }
291           while (a1.IsBound1(aKey1) || a1.IsBound2(aKey2));
292           iFail2--;
293           a1.Bind(aKey1,aKey2);
294         }
295       ////////////////////////////////aTBind.Stop();
296       PERF_STOP_METER("TCollection_DoubleMap binding")
297       ////////////////////////////////aTFind.Start();
298       PERF_START_METER("TCollection_DoubleMap finding")
299       for (j=1; j<=theSize; j++)
300         {
301           Key1Type aKey1;
302           Key2Type aKey2;
303           Random(aKey1);
304           Random(aKey2);
305           a1.AreBound(aKey1,aKey2);
306         }
307       ////////////////////////////////aTFind.Stop();
308       PERF_STOP_METER("TCollection_DoubleMap finding")
309       ////////////////////////////////aTOper.Start();
310       PERF_START_METER("TCollection_DoubleMap operator=")
311       a2 = a1;
312       ////////////////////////////////aTOper.Stop();
313       PERF_STOP_METER("TCollection_DoubleMap operator=")
314       ////////////////////////////////aTClea.Start();
315       PERF_START_METER("TCollection_DoubleMap clearing")
316       a2.Clear();
317       ////////////////////////////////aTClea.Stop();
318       PERF_STOP_METER("TCollection_DoubleMap clearing")
319     }
320   PERF_PRINT_ALL
321   if (iFail1 || iFail2)
322     cout << "Warning : N map failed " << iFail1 << " times, T map - " << 
323       iFail2 << endl;
324 }
325
326 // ===================== Test perform of IndexedMap type ==========================
327 void CompIndexedMap (const Standard_Integer theRep,
328                      const Standard_Integer theSize)
329 {
330   Standard_Integer i,j;
331
332   ////////////////////////////////Perf_Meter aNBind ("NCollection_IndexedMap adding",0);
333   ////////////////////////////////Perf_Meter aTBind ("TCollection_IndexedMap adding",0);
334   ////////////////////////////////Perf_Meter aNOper ("NCollection_IndexedMap operator=",0);
335   ////////////////////////////////Perf_Meter aTOper ("TCollection_IndexedMap operator=",0);
336   ////////////////////////////////Perf_Meter aNFind ("NCollection_IndexedMap finding",0);
337   ////////////////////////////////Perf_Meter aTFind ("TCollection_IndexedMap finding",0);
338   ////////////////////////////////Perf_Meter aNClea ("NCollection_IndexedMap clearing",0);
339   ////////////////////////////////Perf_Meter aTClea ("TCollection_IndexedMap clearing",0);
340   ////////////////////////////////Perf_Meter aNAssi ("NCollection_IndexedMap Assign",0);
341
342   for (i=0; i<theRep; i++)
343     {
344       ////////////////////////////////QANCollection_IndexedMap a1, a2;
345       QANCollection_IndexedMapPerf a1, a2;
346       ////////////////////////////////aNBind.Start();
347       PERF_START_METER("NCollection_IndexedMap adding")
348       for (j=1; j<=theSize; j++)
349         {
350           Key1Type aKey1;
351           Random(aKey1);
352           a1.Add(aKey1);
353         }
354       ////////////////////////////////aNBind.Stop();
355       PERF_STOP_METER("NCollection_IndexedMap adding")
356       ////////////////////////////////aNFind.Start();
357       PERF_START_METER("NCollection_IndexedMap finding")
358       for (j=1; j<=theSize; j++)
359         {
360           Key1Type aKey1;
361           Random(aKey1);
362           a1.Contains(aKey1);
363         }
364       ////////////////////////////////aNFind.Stop();
365       PERF_STOP_METER("NCollection_IndexedMap finding")
366       ////////////////////////////////aNOper.Start();
367       PERF_START_METER("NCollection_IndexedMap operator=")
368       a2 = a1;
369       ////////////////////////////////aNOper.Stop();
370       PERF_STOP_METER("NCollection_IndexedMap operator=")
371       ////////////////////////////////aNAssi.Start();
372       PERF_START_METER("NCollection_IndexedMap Assign")
373       a2.Assign(a1);
374       ////////////////////////////////aNAssi.Stop();
375       PERF_STOP_METER("NCollection_IndexedMap Assign")
376       ////////////////////////////////aNClea.Start();
377       PERF_START_METER("NCollection_IndexedMap clearing")
378       a2.Clear();
379       ////////////////////////////////aNClea.Stop();
380       PERF_STOP_METER("NCollection_IndexedMap clearing")
381     }
382
383   for (i=0; i<theRep; i++)
384     {
385       TColStd_IndexedMapOfReal a1, a2;
386       ////////////////////////////////aTBind.Start();
387       PERF_START_METER("TCollection_IndexedMap adding")
388       for (j=1; j<=theSize; j++)
389         {
390           Key1Type aKey1;
391           Random(aKey1);
392           a1.Add(aKey1);
393         }
394       ////////////////////////////////aTBind.Stop();
395       PERF_STOP_METER("TCollection_IndexedMap adding")
396       ////////////////////////////////aTFind.Start();
397       PERF_START_METER("TCollection_IndexedMap finding")
398       for (j=1; j<=theSize; j++)
399         {
400           Key1Type aKey1;
401           Random(aKey1);
402           a1.Contains(aKey1);
403         }
404       ////////////////////////////////aTFind.Stop();
405       PERF_STOP_METER("TCollection_IndexedMap finding")
406       ////////////////////////////////aTOper.Start();
407       PERF_START_METER("TCollection_IndexedMap operator=")
408       a2 = a1;
409       ////////////////////////////////aTOper.Stop();
410       PERF_STOP_METER("TCollection_IndexedMap operator=")
411       ////////////////////////////////aTClea.Start();
412       PERF_START_METER("TCollection_IndexedMap clearing")
413       a2.Clear();
414       ////////////////////////////////aTClea.Stop();
415       PERF_STOP_METER("TCollection_IndexedMap clearing")
416     }
417   PERF_PRINT_ALL
418 }
419
420 // ===================== Test perform of IndexedDataMap type ==========================
421 void CompIndexedDataMap (const Standard_Integer theRep,
422                          const Standard_Integer theSize)
423 {
424   Standard_Integer i,j;
425
426   ////////////////////////////////Perf_Meter aNBind ("NCollection_IndexedDataMap binding",0);
427   ////////////////////////////////Perf_Meter aTBind ("TCollection_IndexedDataMap binding",0);
428   ////////////////////////////////Perf_Meter aNFind ("NCollection_IndexedDataMap finding",0);
429   ////////////////////////////////Perf_Meter aTFind ("TCollection_IndexedDataMap finding",0);
430   ////////////////////////////////Perf_Meter aNOper ("NCollection_IndexedDataMap operator=",0);
431   ////////////////////////////////Perf_Meter aTOper ("TCollection_IndexedDataMap operator=",0);
432   ////////////////////////////////Perf_Meter aNClea ("NCollection_IndexedDataMap clearing",0);
433   ////////////////////////////////Perf_Meter aTClea ("TCollection_IndexedDataMap clearing",0);
434   //////////////////////////////////Perf_Meter aNAssi ("NCollection_IndexedDataMap Assign",0);
435
436   for (i=0; i<theRep; i++)
437     {
438       ////////////////////////////////QANCollection_IDMap a1, a2;
439       QANCollection_IDMapPerf a1, a2;
440       ////////////////////////////////aNBind.Start();
441       PERF_START_METER("NCollection_IndexedDataMap binding")
442       for (j=1; j<=theSize; j++)
443         {
444           Key1Type aKey1;
445           ItemType anItem;
446           Random(aKey1);
447           Random(anItem);
448           a1.Add(aKey1,anItem);
449         }
450       ////////////////////////////////aNBind.Stop();
451       PERF_STOP_METER("NCollection_IndexedDataMap binding")
452       ////////////////////////////////aNFind.Start();
453       PERF_START_METER("NCollection_IndexedDataMap finding")
454       for (j=1; j<=theSize; j++)
455         {
456           Key1Type aKey1;
457           Random(aKey1);
458           a1.Contains(aKey1);
459         }
460       ////////////////////////////////aNFind.Stop();
461       PERF_STOP_METER("NCollection_IndexedDataMap finding")
462       ////////////////////////////////aNOper.Start();
463       PERF_START_METER("NCollection_IndexedDataMap operator=")
464       a2 = a1;
465       ////////////////////////////////aNOper.Stop();
466       PERF_STOP_METER("NCollection_IndexedDataMap operator=")
467       //aNAssi.Start();
468       //a2.Assign(a1);
469       //aNAssi.Stop();
470       ////////////////////////////////aNClea.Start();
471       PERF_START_METER("NCollection_IndexedDataMap clearing")
472       a2.Clear();
473       ////////////////////////////////aNClea.Stop();
474       PERF_STOP_METER("NCollection_IndexedDataMap clearing")
475     }
476
477   for (i=0; i<theRep; i++)
478     {
479       QANCollection_IndexedDataMapOfRealPnt a1, a2;
480       ////////////////////////////////aTBind.Start();
481       PERF_START_METER("TCollection_IndexedDataMap binding")
482       for (j=1; j<=theSize; j++)
483         {
484           Key1Type aKey1;
485           ItemType anItem;
486           Random(aKey1);
487           Random(anItem);
488           a1.Add(aKey1,anItem);
489         }
490       ////////////////////////////////aTBind.Stop();
491       PERF_STOP_METER("TCollection_IndexedDataMap binding")
492       ////////////////////////////////aTFind.Start();
493       PERF_START_METER("TCollection_IndexedDataMap finding")
494       for (j=1; j<=theSize; j++)
495         {
496           Key1Type aKey1;
497           Random(aKey1);
498           a1.Contains(aKey1);
499         }
500       ////////////////////////////////aTFind.Stop();
501       PERF_STOP_METER("TCollection_IndexedDataMap finding")
502       ////////////////////////////////aTOper.Start();
503       PERF_START_METER("TCollection_IndexedDataMap operator=")
504       a2 = a1;
505       ////////////////////////////////aTOper.Stop();
506       PERF_STOP_METER("TCollection_IndexedDataMap operator=")
507       ////////////////////////////////aTClea.Start();
508       PERF_START_METER("TCollection_IndexedDataMap clearing")
509       a2.Clear();
510       ////////////////////////////////aTClea.Stop();
511       PERF_STOP_METER("TCollection_IndexedDataMap clearing")
512     }
513   PERF_PRINT_ALL
514 }
515
516 #endif