0023880: Integration of grid "ncl" into the new testing system
[occt.git] / src / QANCollection / QANCollection_Simple.cxx
CommitLineData
b311480e 1// Created on: 2004-03-05
2// Created by: Mikhail KUZMITCHEV
973c2be1 3// Copyright (c) 2004-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <QANCollection.hxx>
17#include <Draw_Interpretor.hxx>
18
c2ae831c 19#include <OSD_PerfMeter.hxx>
7fd59977 20
21#include <TColgp_Array1OfPnt.hxx>
22#include <TColgp_SequenceOfPnt.hxx>
23
7fd59977 24#include <NCollection_Sequence.hxx>
25#include <NCollection_Array1.hxx>
3a01a933 26#include <NCollection_IncAllocator.hxx>
27
7fd59977 28typedef NCollection_Array1<gp_Pnt> MyArray1;
29typedef NCollection_Sequence<gp_Pnt> MySequence;
3a01a933 30
31const Standard_Integer REPEAT = 100;
32
618617fe 33static void printAllMeters (Draw_Interpretor& theDI)
3a01a933 34{
618617fe 35 char buffer[25600];
36 perf_sprint_all_meters (buffer, 25600 - 1, 1);
37 theDI << buffer;
3a01a933 38}
39
40static void createArray (TColgp_Array1OfPnt& anArrPnt)
41{
42 OSD_PerfMeter aPerfMeter("Create array");
43
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")
49 }
50}
51
52static void createSequence (TColgp_SequenceOfPnt& aSeq)
53{
54 for (Standard_Integer j = 0; j < REPEAT; j++) {
55 PERF_START_METER("Clear sequence")
56 aSeq.Clear();
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")
62 }
63}
64
65static void createSequence (MySequence& aSeq)
66{
67 for (Standard_Integer j = 0; j < REPEAT; j++) {
68 PERF_START_METER("Clear sequence")
69 aSeq.Clear();
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")
75 }
76}
77
78static void assignSequence (TColgp_SequenceOfPnt& aDest,
79 const TColgp_SequenceOfPnt& aSrc)
80{
81 for (Standard_Integer i = 0; i < REPEAT; i++) {
82 PERF_START_METER("Assign sequence to sequence")
83 aDest = aSrc;
84 PERF_STOP_METER("Assign sequence to sequence")
85 }
86}
87
88static void assignSequence (MySequence& aDest, const MySequence& aSrc)
89{
90 for (Standard_Integer i = 0; i < REPEAT; i++) {
91 PERF_START_METER("Assign sequence to sequence")
92 aDest = aSrc;
93 PERF_STOP_METER("Assign sequence to sequence")
94 }
95}
96
97static void createArray (MyArray1& anArrPnt)
98{
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")
104 }
105}
106
107static void assignArray (TColgp_Array1OfPnt& aDest, const TColgp_Array1OfPnt& aSrc)
108{
109 for (Standard_Integer i = 0; i < 2*REPEAT; i++) {
110 PERF_START_METER("Assign array to array")
111 aDest = aSrc;
112 PERF_STOP_METER("Assign array to array")
113 }
114}
115
116template <class MyBaseCollPnt>
117void assignCollection (MyBaseCollPnt& aDest,
118 const MyBaseCollPnt& aSrc,
119 const char * MeterName)
120{
121 for (Standard_Integer i = 0; i < REPEAT; i++) {
122 perf_start_meter (MeterName);
123 aDest.Assign(aSrc);
124 perf_stop_meter (MeterName);
125 }
126}
127
128static void assignArray (MyArray1& aDest, const MyArray1& aSrc)
129{
130 for (Standard_Integer i = 0; i < 2*REPEAT; i++) {
131 PERF_START_METER("Assign array to array")
132 aDest = aSrc;
133 PERF_STOP_METER("Assign array to array")
134 }
135}
136
618617fe 137static void checkArray (Draw_Interpretor& theDI, const Standard_Boolean isNewColl)
7fd59977 138{
139 if (isNewColl) {
140 MyArray1 anArrPnt (1, 100000), anArrPnt1 (1, 100000);
141 createArray (anArrPnt);
142 assignArray (anArrPnt1, anArrPnt);
143 assignCollection (anArrPnt1, anArrPnt, "Assign collect to array");
144 } else {
145 TColgp_Array1OfPnt anArrPnt (1,100000), anArrPnt1 (1, 100000);
146 createArray (anArrPnt);
147 assignArray (anArrPnt1, anArrPnt);
148 }
618617fe 149 printAllMeters (theDI);
7fd59977 150}
151
618617fe 152static void checkSequence (Draw_Interpretor& theDI,
153 const Standard_Boolean isNewColl,
3a01a933 154 const Standard_Boolean isIncr)
7fd59977 155{
156 if (isNewColl) {
3a01a933 157 Handle(NCollection_BaseAllocator) anAlloc[2];
7fd59977 158 if (isIncr) {
159 anAlloc[0] = new NCollection_IncAllocator;
160 anAlloc[1] = new NCollection_IncAllocator;
161 }
162 MySequence aSeqPnt (anAlloc[0]), aSeqPnt1(anAlloc[1]);
163 createSequence (aSeqPnt);
164 assignSequence (aSeqPnt1, aSeqPnt);
165 assignCollection (aSeqPnt1, aSeqPnt, "Assign collect to sequence");
166 } else {
167 TColgp_SequenceOfPnt aSeqPnt, aSeqPnt1;
168 createSequence (aSeqPnt);
169 assignSequence (aSeqPnt1, aSeqPnt);
170 }
618617fe 171 printAllMeters (theDI);
7fd59977 172}
173
174//=======================================================================
175//function : QANColCheckArray1
176//purpose :
177//=======================================================================
178static Standard_Integer QANColCheckArray1(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
179{
180 if ( argc > 2) {
181 di << "Usage : " << argv[0] << " [-n]" << "\n";
182 return 1;
183 }
184
185 Standard_Boolean isNewColl = Standard_False;
186 if (argc > 1) {
187 if (strcmp (argv[1], "-n") == 0) isNewColl = Standard_True;
188 }
618617fe 189 checkArray (di, isNewColl);
7fd59977 190 return 0;
191}
192
193//=======================================================================
194//function : QANColCheckSequence
195//purpose :
196//=======================================================================
197static Standard_Integer QANColCheckSequence(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
198{
199 if ( argc > 2) {
200 di << "Usage : " << argv[0] << " [-n]/[-ni]/[-in]" << "\n";
201 return 1;
202 }
203
204 Standard_Boolean isNewColl = Standard_False, isIncr = Standard_False;
205 if (argc > 1) {
206 if (strcmp (argv[1], "-n") == 0) isNewColl = Standard_True;
207 if (strcmp (argv[1], "-ni") == 0 || strcmp (argv[1], "-in") == 0)
208 {
209 isNewColl = Standard_True;
210 isIncr = Standard_True;
211 }
212 }
618617fe 213 checkSequence (di, isNewColl, isIncr);
7fd59977 214 return 0;
215}
216
3a01a933 217void QANCollection::CommandsSimple(Draw_Interpretor& theCommands) {
1365140b 218 const char *group = "QANCollection";
7fd59977 219
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);
223
224 return;
225}