0023237: OSD_PerfMeter reports wrong (zero) times
[occt.git] / src / QANCollection / QANCollectionTest.cxx
CommitLineData
b311480e 1// Created on: 2002-04-16
2// Created by: Alexander GRIGORIEV
3// Copyright (c) 2002-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21#include <TColgp_Array1OfPnt.hxx>
22#include <TColgp_SequenceOfPnt.hxx>
23
24#define USE_MACROS
25#ifdef USE_MACROS
26#include <NCollection_DefineArray1.hxx>
27#include <NCollection_DefineSequence.hxx>
28DEFINE_BASECOLLECTION (MyBaseCollPnt, gp_Pnt)
29DEFINE_ARRAY1 (MyArray1, MyBaseCollPnt, gp_Pnt)
30DEFINE_SEQUENCE (MySequence, MyBaseCollPnt, gp_Pnt)
31#else
32#include <NCollection_Sequence.hxx>
33#include <NCollection_Array1.hxx>
34typedef NCollection_Array1<gp_Pnt> MyArray1;
35typedef NCollection_Sequence<gp_Pnt> MySequence;
36typedef NCollection_BaseCollection<gp_Pnt> MyBaseCollPnt;
37#endif
38
39#define PERF_ENABLE_METERS
c2ae831c 40#include <OSD_PerfMeter.hxx>
7fd59977 41
42extern Handle(NCollection_BaseAllocator) getAlloc (const int i);
43
44const Standard_Integer REPEAT = 100;
45
46void createArray (TColgp_Array1OfPnt& anArrPnt)
47{
c2ae831c 48 OSD_PerfMeter aPerfMeter("Create array");
49
7fd59977 50 for (Standard_Integer j = 0; j < 2*REPEAT; j++) {
51 PERF_START_METER("Create array")
52 for (Standard_Integer i = anArrPnt.Lower(); i <= anArrPnt.Upper(); i++)
53 anArrPnt(i).SetCoord ((double)i, (double)(i+1), (double)(i+2));
54 PERF_STOP_METER("Create array")
55 }
56}
57
58void createArray (MyArray1& anArrPnt)
59{
60 for (Standard_Integer j = 0; j < 2*REPEAT; j++) {
61 PERF_START_METER("Create array")
62 for (Standard_Integer i = anArrPnt.Lower(); i <= anArrPnt.Upper(); i++)
63 anArrPnt(i).SetCoord ((double)i, (double)(i+1), (double)(i+2));
64 PERF_STOP_METER("Create array")
65 }
66}
67
68void assignArray (TColgp_Array1OfPnt& aDest, const TColgp_Array1OfPnt& aSrc)
69{
70 for (Standard_Integer i = 0; i < 2*REPEAT; i++) {
71 PERF_START_METER("Assign array to array")
72 aDest = aSrc;
73 PERF_STOP_METER("Assign array to array")
74 }
75}
76
77void assignCollection (MyBaseCollPnt& aDest,
78 const MyBaseCollPnt& aSrc,
79 const char * MeterName)
80{
81 for (Standard_Integer i = 0; i < REPEAT; i++) {
82 perf_start_meter (MeterName);
83// if (getAlloc(1).IsNull() == Standard_False)
84// if (getAlloc(1)->IsKind(STANDARD_TYPE(NCollection_IncAllocator)))
85// Handle(NCollection_IncAllocator)::DownCast(getAlloc(1)) -> Clean();
86 aDest.Assign(aSrc);
87 perf_stop_meter (MeterName);
88 }
89}
90
91void assignArray (MyArray1& aDest,
92 const MyArray1& aSrc)
93{
94 for (Standard_Integer i = 0; i < 2*REPEAT; i++) {
95 PERF_START_METER("Assign array to array")
96 aDest = aSrc;
97 PERF_STOP_METER("Assign array to array")
98 }
99}
100
101void createSequence (TColgp_SequenceOfPnt& aSeq)
102{
103 for (Standard_Integer j = 0; j < REPEAT; j++) {
104 PERF_START_METER("Clear sequence")
105 aSeq.Clear();
106 PERF_STOP_METER("Clear sequence")
107 PERF_START_METER("Create sequence")
108 for (Standard_Integer i = 0; i < 100000; i++)
109 aSeq.Append (gp_Pnt((double)i, (double)(i+1), (double)(i+2)));
110 PERF_STOP_METER("Create sequence")
111 }
112}
113
114void createSequence (MySequence& aSeq)
115{
116 for (Standard_Integer j = 0; j < REPEAT; j++) {
117 PERF_START_METER("Clear sequence")
118 aSeq.Clear();
119// if (getAlloc(0).IsNull() == Standard_False)
120// if (getAlloc(0)->IsKind(STANDARD_TYPE(NCollection_IncAllocator)))
121// Handle(NCollection_IncAllocator)::DownCast(getAlloc(0)) -> Clean();
122 PERF_STOP_METER("Clear sequence")
123 PERF_START_METER("Create sequence")
124 for (Standard_Integer i = 0; i < 100000; i++)
125 aSeq.Append (gp_Pnt((double)i, (double)(i+1), (double)(i+2)));
126 PERF_STOP_METER("Create sequence")
127 }
128}
129
130void assignSequence (TColgp_SequenceOfPnt& aDest,
131 const TColgp_SequenceOfPnt& aSrc)
132{
133 for (Standard_Integer i = 0; i < REPEAT; i++) {
134 PERF_START_METER("Assign sequence to sequence")
135 aDest = aSrc;
136 PERF_STOP_METER("Assign sequence to sequence")
137 }
138}
139
140void assignSequence (MySequence& aDest, const MySequence& aSrc)
141{
142 for (Standard_Integer i = 0; i < REPEAT; i++) {
143 PERF_START_METER("Assign sequence to sequence")
144// if (getAlloc(1).IsNull() == Standard_False)
145// if (getAlloc(1)->IsKind(STANDARD_TYPE(NCollection_IncAllocator)))
146// Handle(NCollection_IncAllocator)::DownCast(getAlloc(1)) -> Clean();
147 aDest = aSrc;
148 PERF_STOP_METER("Assign sequence to sequence")
149 }
150}
151
152void printAllMeters ()
153{
c2ae831c 154 PERF_PRINT_ALL
7fd59977 155}