Qt 6.x
The Qt SDK
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
18{
19 setMode(mode_);
20}
21
23{
24 delete measurer;
27}
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
63{
64 return medianIterationCount != -1
66}
67
68
70
72
74{
76}
77
79{
81}
82
84{
85}
86
88{
89 // Let the -iterations option override the measurer.
92 } else {
94 }
95
96 return iterationCount;
97}
98
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
148{
149 i = 0;
150 if (runMode == RunOnce)
153}
154
156{
157 i = 0;
159}
160
164{
166}
167
171{
173 return i > 0;
174 return i >= QTest::iterationCount();
175}
176
180{
181 ++i;
182}
183
187{
189}
190
194{
196}
197
201{
204}
205
209{
211 // the clock is ticking after the line above, don't add code here.
212}
213
217{
218 // the clock is ticking before the line below, don't add code here.
220}
221
240{
242}
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)
QBenchmarkContext context
QBenchmarkMeasurerBase * measurer
QBenchmarkMeasurerBase * createMeasurer()
static QBenchmarkGlobalData * current
virtual bool isMeasurementAccepted(Measurement m)=0
virtual void start()=0
virtual int adjustIterationCount(int suggestion)=0
virtual int adjustMedianCount(int suggestion)=0
virtual QList< Measurement > stop()=0
static QBenchmarkTestMethodData * current
int adjustIterationCount(int suggestion)
void setResults(const QList< QBenchmarkMeasurerBase::Measurement > &m, bool setByMacro=true)
QList< QBenchmarkResult > results
void setResult(QBenchmarkMeasurerBase::Measurement m, bool setByMacro=true)
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
bool isEmpty() const noexcept
Definition qlist.h:390
reference emplaceBack(Args &&... args)
Definition qlist.h:875
const T & constFirst() const noexcept
Definition qlist.h:630
void reserve(qsizetype size)
Definition qlist.h:746
const_iterator constBegin() const noexcept
Definition qset.h:139
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()
int iterationCount()
void setIterationCountHint(int count)
void setIterationCount(int count)
void beginBenchmarkMeasurement()
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:92
QList< int > list
[14]