qbenchmark.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/testlib/qbenchmark.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5QBenchmarkGlobalData *QBenchmarkGlobalData::current;-
6-
7QBenchmarkGlobalData::QBenchmarkGlobalData()-
8 : measurer(0)-
9 , walltimeMinimum(-1)-
10 , iterationCount(-1)-
11 , medianIterationCount(-1)-
12 , createChart(false)-
13 , verboseOutput(false)-
14 , minimumTotal(-1)-
15 , mode_(WallTime)-
16{-
17 setMode(mode_);-
18}-
19-
20QBenchmarkGlobalData::~QBenchmarkGlobalData()-
21{-
22 delete measurer;-
23 QBenchmarkGlobalData::current = 0;-
24}-
25-
26void QBenchmarkGlobalData::setMode(Mode mode)-
27{-
28 mode_ = mode;-
29-
30 if (measurer)-
31 delete measurer;-
32 measurer = createMeasurer();-
33}-
34-
35QBenchmarkMeasurerBase * QBenchmarkGlobalData::createMeasurer()-
36{-
37 QBenchmarkMeasurerBase *measurer = 0;-
38 if (0) {
dead code: { }
-
39-
40 }
dead code: { }
else if (mode_ == CallgrindChildProcess || mode_ == CallgrindParentProcess) {
-
41 measurer = new QBenchmarkCallgrindMeasurer;-
42-
43-
44 } else if (mode_ == PerfCounter) {-
45 measurer = new QBenchmarkPerfEventsMeasurer;-
46-
47-
48 } else if (mode_ == TickCounter) {-
49 measurer = new QBenchmarkTickMeasurer;-
50-
51 } else if (mode_ == EventCounter) {-
52 measurer = new QBenchmarkEvent;-
53 } else {-
54 measurer = new QBenchmarkTimeMeasurer;-
55 }-
56 measurer->init();-
57 return measurer;-
58}-
59-
60int QBenchmarkGlobalData::adjustMedianIterationCount()-
61{-
62 if (medianIterationCount != -1) {-
63 return medianIterationCount;-
64 } else {-
65 return measurer->adjustMedianCount(1);-
66 }-
67}-
68-
69-
70QBenchmarkTestMethodData *QBenchmarkTestMethodData::current;-
71-
72QBenchmarkTestMethodData::QBenchmarkTestMethodData()-
73:resultAccepted(false), runOnce(false), iterationCount(-1)-
74{-
75}-
76-
77QBenchmarkTestMethodData::~QBenchmarkTestMethodData()-
78{-
79 QBenchmarkTestMethodData::current = 0;-
80}-
81-
82void QBenchmarkTestMethodData::beginDataRun()-
83{-
84 iterationCount = adjustIterationCount(1);-
85}-
86-
87void QBenchmarkTestMethodData::endDataRun()-
88{-
89}-
90-
91int QBenchmarkTestMethodData::adjustIterationCount(int suggestion)-
92{-
93-
94 if (QBenchmarkGlobalData::current->iterationCount != -1) {-
95 iterationCount = QBenchmarkGlobalData::current->iterationCount;-
96 } else {-
97 iterationCount = QBenchmarkGlobalData::current->measurer->adjustIterationCount(suggestion);-
98 }-
99-
100 return iterationCount;-
101}-
102-
103void QBenchmarkTestMethodData::setResult(-
104 qreal value, QTest::QBenchmarkMetric metric, bool setByMacro)-
105{-
106 bool accepted = false;-
107-
108-
109-
110 if (QBenchmarkGlobalData::current->iterationCount != -1)-
111 accepted = true;-
112-
113 else if (QBenchmarkTestMethodData::current->runOnce || !setByMacro) {-
114 iterationCount = 1;-
115 accepted = true;-
116 }-
117-
118-
119-
120 else if (QBenchmarkGlobalData::current->walltimeMinimum != -1)-
121 accepted = (value > QBenchmarkGlobalData::current->walltimeMinimum);-
122 else-
123 accepted = QBenchmarkGlobalData::current->measurer->isMeasurementAccepted(value);-
124-
125-
126 if (accepted)-
127 resultAccepted = true;-
128 else-
129 iterationCount *= 2;-
130-
131 this->result = QBenchmarkResult(-
132 QBenchmarkGlobalData::current->context, value, iterationCount, metric, setByMacro);-
133}-
134QTest::QBenchmarkIterationController::QBenchmarkIterationController(RunMode runMode)-
135{-
136 i = 0;-
137 if (runMode == RunOnce)-
138 QBenchmarkTestMethodData::current->runOnce = true;-
139 QTest::beginBenchmarkMeasurement();-
140}-
141-
142QTest::QBenchmarkIterationController::QBenchmarkIterationController()-
143{-
144 i = 0;-
145 QTest::beginBenchmarkMeasurement();-
146}-
147-
148-
149-
150QTest::QBenchmarkIterationController::~QBenchmarkIterationController()-
151{-
152 const qreal result = QTest::endBenchmarkMeasurement();-
153 QBenchmarkTestMethodData::current->setResult(result, QBenchmarkGlobalData::current->measurer->metricType());-
154}-
155-
156-
157-
158bool QTest::QBenchmarkIterationController::isDone()-
159{-
160 if (QBenchmarkTestMethodData::current->runOnce)-
161 return i > 0;-
162 return i >= QTest::iterationCount();-
163}-
164-
165-
166-
167void QTest::QBenchmarkIterationController::next()-
168{-
169 ++i;-
170}-
171-
172-
173-
174int QTest::iterationCount()-
175{-
176 return QBenchmarkTestMethodData::current->iterationCount;-
177}-
178-
179-
180-
181void QTest::setIterationCountHint(int count)-
182{-
183 QBenchmarkTestMethodData::current->adjustIterationCount(count);-
184}-
185-
186-
187-
188void QTest::setIterationCount(int count)-
189{-
190 QBenchmarkTestMethodData::current->iterationCount = count;-
191 QBenchmarkTestMethodData::current->resultAccepted = true;-
192}-
193-
194-
195-
196void QTest::beginBenchmarkMeasurement()-
197{-
198 QBenchmarkGlobalData::current->measurer->start();-
199-
200}-
201-
202-
203-
204quint64 QTest::endBenchmarkMeasurement()-
205{-
206-
207 return QBenchmarkGlobalData::current->measurer->stop();-
208}-
209void QTest::setBenchmarkResult(qreal result, QTest::QBenchmarkMetric metric)-
210{-
211 QBenchmarkTestMethodData::current->setResult(result, metric, false);-
212}-
213-
214template <typename T>-
215typename T::value_type qAverage(const T &container)-
216{-
217 typename T::const_iterator it = container.constBegin();-
218 typename T::const_iterator end = container.constEnd();-
219 typename T::value_type acc = typename T::value_type();-
220 int count = 0;-
221 while (it != end) {-
222 acc += *it;-
223 ++it;-
224 ++count;-
225 }-
226 return acc / count;-
227}-
228-
229-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9