Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qbenchmarkevent.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/private/qbenchmarkevent_p.h>
5#include <QtTest/private/qbenchmark_p.h>
6#include <QtTest/private/qbenchmarkmetric_p.h>
7#include <qdebug.h>
8
10
11QBenchmarkEvent::QBenchmarkEvent() = default;
12
13QBenchmarkEvent::~QBenchmarkEvent() = default;
14
15void QBenchmarkEvent::start()
16{
17 eventCounter = 0;
18 QAbstractEventDispatcher::instance()->installNativeEventFilter(this);
19}
20
21void QBenchmarkEvent::updateMeasurement()
22{
23 QAbstractEventDispatcher::instance()->removeNativeEventFilter(this);
24 accumulator.update(qreal(eventCounter));
25 eventCounter = 0;
26 QAbstractEventDispatcher::instance()->installNativeEventFilter(this);
27}
28
29QList<QBenchmarkMeasurerBase::Measurement> QBenchmarkEvent::stop()
30{
31 QAbstractEventDispatcher::instance()->removeNativeEventFilter(this);
32 return { { accumulator.total(),
33 accumulator.variance() / QBenchmarkTestMethodData::current->measurementBlockSize,
34 QTest::Events } };
35}
36
37// It's very tempting to simply reject a measurement if 0 events
38// where counted, however that is a possible situation and returning
39// false here will create a infinite loop. Do not change this.
40bool QBenchmarkEvent::isMeasurementAccepted(QBenchmarkMeasurerBase::Measurement measurement)
41{
42 Q_UNUSED(measurement);
43 return true;
44}
45
46int QBenchmarkEvent::adjustIterationCount(int suggestion)
47{
48 return suggestion;
49}
50
51int QBenchmarkEvent::adjustMedianCount(int suggestion)
52{
53 Q_UNUSED(suggestion);
54 return 1;
55}
56
57// This could be done in a much better way, this is just the beginning.
58bool QBenchmarkEvent::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
59{
60 Q_UNUSED(eventType);
61 Q_UNUSED(message);
62 Q_UNUSED(result);
63
64 eventCounter++;
65 return false;
66}
67
68QT_END_NAMESPACE
Combined button and popup list for selecting options.