mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-08 02:17:43 +08:00
qt 6.5.1 original
This commit is contained in:
5
tests/benchmarks/corelib/io/qprocess/CMakeLists.txt
Normal file
5
tests/benchmarks/corelib/io/qprocess/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
add_subdirectory(testProcessLoopback)
|
||||
add_subdirectory(test)
|
14
tests/benchmarks/corelib/io/qprocess/test/CMakeLists.txt
Normal file
14
tests/benchmarks/corelib/io/qprocess/test/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_bench_qprocess Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_benchmark(tst_bench_qprocess
|
||||
SOURCES
|
||||
../tst_bench_qprocess.cpp
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::Test
|
||||
)
|
@ -0,0 +1,8 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## testProcessLoopback Binary:
|
||||
#####################################################################
|
||||
|
||||
add_executable(testProcessLoopback loopback.cpp)
|
@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char buffer[1024];
|
||||
for (;;) {
|
||||
size_t num = fread(buffer, 1, sizeof(buffer), stdin);
|
||||
if (num <= 0)
|
||||
break;
|
||||
fwrite(buffer, num, 1, stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
70
tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp
Normal file
70
tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright (C) 2021 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
#include <QtCore/QProcess>
|
||||
#include <QtCore/QElapsedTimer>
|
||||
|
||||
class tst_QProcess : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
|
||||
void echoTest_performance();
|
||||
};
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
# define EXE ".exe"
|
||||
#else
|
||||
# define EXE ""
|
||||
#endif
|
||||
|
||||
void tst_QProcess::echoTest_performance()
|
||||
{
|
||||
QProcess process;
|
||||
process.start(QFINDTESTDATA("../testProcessLoopback/testProcessLoopback" EXE));
|
||||
|
||||
QByteArray array;
|
||||
array.resize(1024 * 1024);
|
||||
for (int j = 0; j < array.size(); ++j)
|
||||
array[j] = 'a' + (j % 20);
|
||||
|
||||
QVERIFY(process.waitForStarted());
|
||||
|
||||
QElapsedTimer stopWatch;
|
||||
stopWatch.start();
|
||||
|
||||
qint64 totalBytes = 0;
|
||||
QByteArray dump;
|
||||
QSignalSpy readyReadSpy(&process, SIGNAL(readyRead()));
|
||||
QVERIFY(readyReadSpy.isValid());
|
||||
while (stopWatch.elapsed() < 2000) {
|
||||
process.write(array);
|
||||
while (process.bytesToWrite() > 0) {
|
||||
int readCount = readyReadSpy.size();
|
||||
QVERIFY(process.waitForBytesWritten(5000));
|
||||
if (readyReadSpy.size() == readCount)
|
||||
QVERIFY(process.waitForReadyRead(5000));
|
||||
}
|
||||
|
||||
while (process.bytesAvailable() < array.size())
|
||||
QVERIFY2(process.waitForReadyRead(5000), qPrintable(process.errorString()));
|
||||
dump = process.readAll();
|
||||
totalBytes += dump.size();
|
||||
}
|
||||
|
||||
qDebug() << "Elapsed time:" << stopWatch.elapsed() << "ms;"
|
||||
<< "transfer rate:" << totalBytes / (1048.576) / stopWatch.elapsed()
|
||||
<< "MB/s";
|
||||
|
||||
for (int j = 0; j < array.size(); ++j)
|
||||
QCOMPARE(char(dump.at(j)), char('a' + (j % 20)));
|
||||
|
||||
process.closeWriteChannel();
|
||||
QVERIFY(process.waitForFinished());
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QProcess)
|
||||
#include "tst_bench_qprocess.moc"
|
Reference in New Issue
Block a user