1 // Created on: 2004-03-05
2 // Created by: Mikhail KUZMITCHEV
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <QANCollection.hxx>
17 #include <Draw_Interpretor.hxx>
19 #include <OSD_PerfMeter.hxx>
21 #include <TColgp_Array1OfPnt.hxx>
22 #include <TColgp_SequenceOfPnt.hxx>
24 #include <NCollection_Sequence.hxx>
25 #include <NCollection_Array1.hxx>
26 #include <NCollection_IncAllocator.hxx>
28 typedef NCollection_Array1<gp_Pnt> MyArray1;
29 typedef NCollection_Sequence<gp_Pnt> MySequence;
31 const Standard_Integer REPEAT = 100;
33 static void printAllMeters (Draw_Interpretor& theDI)
36 perf_sprint_all_meters (buffer, 25600 - 1, 1);
40 static void createArray (TColgp_Array1OfPnt& anArrPnt)
42 OSD_PerfMeter aPerfMeter("Create array");
44 for (Standard_Integer j = 0; j < 2*REPEAT; j++) {
45 PERF_START_METER("Create array")
46 for (Standard_Integer i = anArrPnt.Lower(); i <= anArrPnt.Upper(); i++)
47 anArrPnt(i).SetCoord ((double)i, (double)(i+1), (double)(i+2));
48 PERF_STOP_METER("Create array")
52 static void createSequence (TColgp_SequenceOfPnt& aSeq)
54 for (Standard_Integer j = 0; j < REPEAT; j++) {
55 PERF_START_METER("Clear sequence")
57 PERF_STOP_METER("Clear sequence")
58 PERF_START_METER("Create sequence")
59 for (Standard_Integer i = 0; i < 100000; i++)
60 aSeq.Append (gp_Pnt((double)i, (double)(i+1), (double)(i+2)));
61 PERF_STOP_METER("Create sequence")
65 static void createSequence (MySequence& aSeq)
67 for (Standard_Integer j = 0; j < REPEAT; j++) {
68 PERF_START_METER("Clear sequence")
70 PERF_STOP_METER("Clear sequence")
71 PERF_START_METER("Create sequence")
72 for (Standard_Integer i = 0; i < 100000; i++)
73 aSeq.Append (gp_Pnt((double)i, (double)(i+1), (double)(i+2)));
74 PERF_STOP_METER("Create sequence")
78 static void assignSequence (TColgp_SequenceOfPnt& aDest,
79 const TColgp_SequenceOfPnt& aSrc)
81 for (Standard_Integer i = 0; i < REPEAT; i++) {
82 PERF_START_METER("Assign sequence to sequence")
84 PERF_STOP_METER("Assign sequence to sequence")
88 static void assignSequence (MySequence& aDest, const MySequence& aSrc)
90 for (Standard_Integer i = 0; i < REPEAT; i++) {
91 PERF_START_METER("Assign sequence to sequence")
93 PERF_STOP_METER("Assign sequence to sequence")
97 static void createArray (MyArray1& anArrPnt)
99 for (Standard_Integer j = 0; j < 2*REPEAT; j++) {
100 PERF_START_METER("Create array")
101 for (Standard_Integer i = anArrPnt.Lower(); i <= anArrPnt.Upper(); i++)
102 anArrPnt(i).SetCoord ((double)i, (double)(i+1), (double)(i+2));
103 PERF_STOP_METER("Create array")
107 static void assignArray (TColgp_Array1OfPnt& aDest, const TColgp_Array1OfPnt& aSrc)
109 for (Standard_Integer i = 0; i < 2*REPEAT; i++) {
110 PERF_START_METER("Assign array to array")
112 PERF_STOP_METER("Assign array to array")
116 template <class MyBaseCollPnt>
117 void assignCollection (MyBaseCollPnt& aDest,
118 const MyBaseCollPnt& aSrc,
119 const char * MeterName)
121 for (Standard_Integer i = 0; i < REPEAT; i++) {
122 perf_start_meter (MeterName);
124 perf_stop_meter (MeterName);
128 static void assignArray (MyArray1& aDest, const MyArray1& aSrc)
130 for (Standard_Integer i = 0; i < 2*REPEAT; i++) {
131 PERF_START_METER("Assign array to array")
133 PERF_STOP_METER("Assign array to array")
137 static void checkArray (Draw_Interpretor& theDI, const Standard_Boolean isNewColl)
140 MyArray1 anArrPnt (1, 100000), anArrPnt1 (1, 100000);
141 createArray (anArrPnt);
142 assignArray (anArrPnt1, anArrPnt);
143 assignCollection (anArrPnt1, anArrPnt, "Assign collect to array");
145 TColgp_Array1OfPnt anArrPnt (1,100000), anArrPnt1 (1, 100000);
146 createArray (anArrPnt);
147 assignArray (anArrPnt1, anArrPnt);
149 printAllMeters (theDI);
152 static void checkSequence (Draw_Interpretor& theDI,
153 const Standard_Boolean isNewColl,
154 const Standard_Boolean isIncr)
157 Handle(NCollection_BaseAllocator) anAlloc[2];
159 anAlloc[0] = new NCollection_IncAllocator;
160 anAlloc[1] = new NCollection_IncAllocator;
162 MySequence aSeqPnt (anAlloc[0]), aSeqPnt1(anAlloc[1]);
163 createSequence (aSeqPnt);
164 assignSequence (aSeqPnt1, aSeqPnt);
165 assignCollection (aSeqPnt1, aSeqPnt, "Assign collect to sequence");
167 TColgp_SequenceOfPnt aSeqPnt, aSeqPnt1;
168 createSequence (aSeqPnt);
169 assignSequence (aSeqPnt1, aSeqPnt);
171 printAllMeters (theDI);
174 //=======================================================================
175 //function : QANColCheckArray1
177 //=======================================================================
178 static Standard_Integer QANColCheckArray1(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
181 di << "Usage : " << argv[0] << " [-n]" << "\n";
185 Standard_Boolean isNewColl = Standard_False;
187 if (strcmp (argv[1], "-n") == 0) isNewColl = Standard_True;
189 checkArray (di, isNewColl);
193 //=======================================================================
194 //function : QANColCheckSequence
196 //=======================================================================
197 static Standard_Integer QANColCheckSequence(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
200 di << "Usage : " << argv[0] << " [-n]/[-ni]/[-in]" << "\n";
204 Standard_Boolean isNewColl = Standard_False, isIncr = Standard_False;
206 if (strcmp (argv[1], "-n") == 0) isNewColl = Standard_True;
207 if (strcmp (argv[1], "-ni") == 0 || strcmp (argv[1], "-in") == 0)
209 isNewColl = Standard_True;
210 isIncr = Standard_True;
213 checkSequence (di, isNewColl, isIncr);
217 void QANCollection::CommandsSimple(Draw_Interpretor& theCommands) {
218 const char *group = "QANCollection";
220 // from agvCollTest/src/AgvColEXE/TestEXE.cxx
221 theCommands.Add("QANColCheckArray1", "QANColCheckArray1 [-n]", __FILE__, QANColCheckArray1, group);
222 theCommands.Add("QANColCheckSequence", "QANColCheckSequence [-n]/[-ni]/[-in]", __FILE__, QANColCheckSequence, group);