Make a benchmark out of tst_QObjectPerformance::emitToManyReceivers

The test has been flaky on top of QEMU. The test is clearly a sort of manually
rolled benchmark, not a regular autotest. Remove the test and replace it with a
benchmark in QObjectBenchmark.

Task-number: QTBUG-66823
Task-number: QTBUG-66216
Change-Id: I7a48293023f32141eed6fea50fbb63af18933a8f
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Kari Oikarinen 2018-03-02 16:36:06 +02:00 committed by Sami Nurmenniemi
parent e16c6dfb72
commit caa5a20479
5 changed files with 24 additions and 120 deletions

View File

@ -16,7 +16,6 @@ SUBDIRS=\
qcomplextext \
qfocusevent \
qnetworkaccessmanager_and_qprogressdialog \
qobjectperformance \
qobjectrace \
qsharedpointer_and_qwidget \
qprocess_and_guieventloop \
@ -44,7 +43,6 @@ SUBDIRS=\
lancelot \
networkselftest \
qnetworkaccessmanager_and_qprogressdialog \
qobjectperformance
cross_compile: SUBDIRS -= \
atwrapper \

View File

@ -1 +0,0 @@
tst_qobjectperformance

View File

@ -1,7 +0,0 @@
CONFIG += testcase
TARGET = tst_qobjectperformance
SOURCES += tst_qobjectperformance.cpp
QT = core network testlib

View File

@ -1,110 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtTest/QtTest>
#include <qcoreapplication.h>
#include <qobject.h>
class tst_QObjectPerformance : public QObject
{
Q_OBJECT
public:
private slots:
void emitToManyReceivers();
};
class SimpleSenderObject : public QObject
{
Q_OBJECT
signals:
void signal();
public:
void emitSignal()
{
emit signal();
}
};
class SimpleReceiverObject : public QObject
{
Q_OBJECT
public slots:
void slot()
{
}
};
void tst_QObjectPerformance::emitToManyReceivers()
{
// ensure that emission times remain mostly linear as the number of receivers increase
SimpleSenderObject sender;
int elapsed = 0;
const int increase = 3000;
const int base = 5000;
for (int i = 0; i < 4; ++i) {
const int size = base + i * increase;
const double increaseRatio = double(size) / (double)(size - increase);
QList<SimpleReceiverObject *> receivers;
for (int k = 0; k < size; ++k) {
SimpleReceiverObject *receiver = new SimpleReceiverObject;
QObject::connect(&sender, SIGNAL(signal()), receiver, SLOT(slot()));
receivers.append(receiver);
}
QTime timer;
timer.start();
sender.emitSignal();
int e = timer.elapsed();
if (elapsed > 1) {
qDebug() << size << "receivers, elapsed time" << e << "compared to previous time" << elapsed;
QVERIFY(double(e) / double(elapsed) <= increaseRatio * 2.0);
} else {
qDebug() << size << "receivers, elapsed time" << e << "cannot be compared to previous, unmeasurable time";
}
elapsed = e;
qDeleteAll(receivers);
receivers.clear();
}
}
QTEST_MAIN(tst_QObjectPerformance)
#include "tst_qobjectperformance.moc"

View File

@ -43,6 +43,8 @@ Q_OBJECT
private slots:
void signal_slot_benchmark();
void signal_slot_benchmark_data();
void signal_many_receivers();
void signal_many_receivers_data();
void qproperty_benchmark_data();
void qproperty_benchmark();
void dynamic_property_benchmark();
@ -127,6 +129,28 @@ void QObjectBenchmark::signal_slot_benchmark()
}
}
void QObjectBenchmark::signal_many_receivers_data()
{
QTest::addColumn<int>("receiverCount");
QTest::newRow("100 receivers") << 100;
QTest::newRow("1 000 receivers") << 1000;
QTest::newRow("10 000 receivers") << 10000;
}
void QObjectBenchmark::signal_many_receivers()
{
QFETCH(int, receiverCount);
Object sender;
std::vector<Object> receivers(receiverCount);
for (Object &receiver : receivers)
QObject::connect(&sender, &Object::signal0, &receiver, &Object::slot0);
QBENCHMARK {
sender.emitSignal0();
}
}
void QObjectBenchmark::qproperty_benchmark_data()
{
QTest::addColumn<QByteArray>("name");