Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qbenchmark.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtTest/qbenchmark.h>
5#include <QtTest/private/qbenchmark_p.h>
6#include <QtTest/private/qbenchmarkmetric_p.h>
7#include <QtTest/private/qbenchmarktimemeasurers_p.h>
8
9#include <QtCore/qdir.h>
10#include <QtCore/qset.h>
11#include <QtCore/qdebug.h>
12
14
16
21
28
30{
31 mode_ = mode;
32
33 delete measurer;
35}
36
38{
40 if (0) {
41#if QT_CONFIG(valgrind)
42 } else if (mode_ == CallgrindChildProcess || mode_ == CallgrindParentProcess) {
44#endif
45#ifdef QTESTLIB_USE_PERF_EVENTS
46 } else if (mode_ == PerfCounter) {
48#endif
49#ifdef HAVE_TICK_COUNTER
50 } else if (mode_ == TickCounter) {
51 measurer = new QBenchmarkTickMeasurer;
52#endif
53 } else if (mode_ == EventCounter) {
55 } else {
57 }
58 measurer->init();
59 return measurer;
60}
61
67
68
70
72
77
82
86
88{
89 // Let the -iterations option override the measurer.
92 } else {
93 iterationCount = QBenchmarkGlobalData::current->measurer->adjustIterationCount(suggestion);
94 }
95
96 return iterationCount;
97}
98
99void QBenchmarkTestMethodData::setResults(const QList<QBenchmarkMeasurerBase::Measurement> &list,
100 bool setByMacro)
101{
102 bool accepted = false;
103 QBenchmarkMeasurerBase::Measurement firstMeasurement = {};
104 if (!list.isEmpty())
105 firstMeasurement = list.constFirst();
106
107 // Always accept the result if the iteration count has been
108 // specified on the command line with -iterations.
110 accepted = true;
111
112 else if (QBenchmarkTestMethodData::current->runOnce || !setByMacro) {
113 iterationCount = 1;
114 accepted = true;
115 }
116
117 // Test the result directly without calling the measurer if the minimum time
118 // has been specified on the command line with -minimumvalue.
119 else if (QBenchmarkGlobalData::current->walltimeMinimum != -1)
120 accepted = (firstMeasurement.value > QBenchmarkGlobalData::current->walltimeMinimum);
121 else
122 accepted = QBenchmarkGlobalData::current->measurer->isMeasurementAccepted(firstMeasurement);
123
124 // Accept the result or double the number of iterations.
125 if (accepted)
126 resultAccepted = true;
127 else
128 iterationCount *= 2;
129
130 valid = true;
132 for (auto m : list)
134}
135
154
160
167
171{
173 return i > 0;
174 return i >= QTest::iterationCount();
175}
176
180{
181 ++i;
182}
183
187{
188 return QBenchmarkTestMethodData::current->iterationCount;
189}
190
194{
195 QBenchmarkTestMethodData::current->adjustIterationCount(count);
196}
197
201{
203 QBenchmarkTestMethodData::current->resultAccepted = true;
204}
205
209{
210 QBenchmarkGlobalData::current->measurer->start();
211 // the clock is ticking after the line above, don't add code here.
212}
213
216QList<QBenchmarkMeasurerBase::Measurement> QTest::endBenchmarkMeasurement()
217{
218 // the clock is ticking before the line below, don't add code here.
219 return QBenchmarkGlobalData::current->measurer->stop();
220}
221
243
244template <typename T>
245typename T::value_type qAverage(const T &container)
246{
247 typename T::const_iterator it = container.constBegin();
248 typename T::const_iterator end = container.constEnd();
249 typename T::value_type acc = typename T::value_type();
250 int count = 0;
251 while (it != end) {
252 acc += *it;
253 ++it;
254 ++count;
255 }
256 return acc / count;
257}
258
void setMode(Mode mode)
QBenchmarkMeasurerBase * measurer
QBenchmarkMeasurerBase * createMeasurer()
static QBenchmarkGlobalData * current
virtual int adjustMedianCount(int suggestion)=0
static QBenchmarkTestMethodData * current
int adjustIterationCount(int suggestion)
void setResults(const QList< QBenchmarkMeasurerBase::Measurement > &m, bool setByMacro=true)
QList< QBenchmarkResult > results
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
reference emplaceBack(Args &&... args)
Definition qlist.h:882
const T & constFirst() const noexcept
Definition qlist.h:647
void reserve(qsizetype size)
Definition qlist.h:753
QSet< QString >::iterator it
Combined button and popup list for selecting options.
void Q_TESTLIB_EXPORT setBenchmarkResult(qreal result, QBenchmarkMetric metric)
Sets the benchmark result for this test function to result.
QList< QBenchmarkMeasurerBase::Measurement > endBenchmarkMeasurement()
void setIterationCountHint(int count)
void setIterationCount(int count)
void beginBenchmarkMeasurement()
int iterationCount() noexcept
T::value_type qAverage(const T &container)
GLenum mode
const GLfloat * m
GLuint GLuint end
GLenum GLenum GLsizei count
GLuint64EXT * result
[6]
double qreal
Definition qtypes.h:187
QList< int > list
[14]