From 0992182965d21ce2a8c1325205923a4ecd341e40 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 24 Feb 2017 14:51:26 +0100 Subject: Start sequential read at random offset; don't re-init prng every time --- src/copythread.cpp | 11 ++++++++--- src/speedcheck.cpp | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/copythread.cpp b/src/copythread.cpp index 1f9ec2f..5b9710b 100644 --- a/src/copythread.cpp +++ b/src/copythread.cpp @@ -9,6 +9,8 @@ // 20 seconds for each test #define TEST_LENGTH (60000) +#define BIGRAND (qint64(qrand()) | (qint64(qrand()) * qint64(RAND_MAX))) + CopyThread::CopyThread(QFile *file, QObject *parent) : QThread(parent), _doStop(false) @@ -35,8 +37,13 @@ void CopyThread::run() qint64 seqSum = 0, rndSum = 0; qint64 seqTime, rndTime = -1; + const qint64 size = _file->size() - BUFFER_SIZE; + // Sequential read emit logMessage(trUtf8("Starting sequential read test")); + if (size > 0) { + _file->seek(BIGRAND % size); + } timer.start(); do { ret = _file->read(buffer, BUFFER_SIZE); @@ -48,13 +55,11 @@ void CopyThread::run() seqTime = timer.elapsed(); // Random read - qsrand((uint)QCoreApplication::applicationPid()); - const qint64 size = _file->size() - BUFFER_SIZE; if (size > 0) { emit logMessage(trUtf8("Starting random read test")); timer.restart(); do { - _file->seek(((qint64)qrand() ^ ((qint64)qrand() << 15)) % size); + _file->seek(BIGRAND % size); ret = _file->read(buffer, BUFFER_SIZE); rndSum += ret; } while (!_doStop && ret > 0 && timer.elapsed() < TEST_LENGTH); diff --git a/src/speedcheck.cpp b/src/speedcheck.cpp index 8ff8c93..b4dd718 100644 --- a/src/speedcheck.cpp +++ b/src/speedcheck.cpp @@ -21,6 +21,7 @@ SpeedCheck::SpeedCheck(QString fileName) connect(_ui->btnQuit, SIGNAL(clicked(bool)), this, SLOT(quitClicked(bool))); _timer.setInterval(200); connect(&_timer, SIGNAL(timeout()), this, SLOT(updateTimer())); + qsrand((uint)QCoreApplication::applicationPid()); } SpeedCheck::~SpeedCheck() -- cgit v1.2.3-55-g7522