summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2017-02-24 14:51:26 +0100
committerSimon Rettberg2017-02-24 14:51:26 +0100
commit0992182965d21ce2a8c1325205923a4ecd341e40 (patch)
treee6818a4620ccffb8a7e9bb78521fd1c908ba6f00
parentinitial commit (diff)
downloadspeedcheck-0992182965d21ce2a8c1325205923a4ecd341e40.tar.gz
speedcheck-0992182965d21ce2a8c1325205923a4ecd341e40.tar.xz
speedcheck-0992182965d21ce2a8c1325205923a4ecd341e40.zip
Start sequential read at random offset; don't re-init prng every time
-rw-r--r--src/copythread.cpp11
-rw-r--r--src/speedcheck.cpp1
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()