Skip to content

Performance Qt SHA1 vs OpenSSL SHA1 #5312

@guruz

Description

@guruz

@ogoffart mentioned that checksum calculation takes 90% of his CPU load when syncing.
I evaluated if OpenSSL sha1 is faster than Qt sha1 and unfortunately it is not.
Just an FYI @dragotin @ckamm etc

diff --git a/src/gui/main.cpp b/src/gui/main.cpp
index 003fcfd..5ea728b 100644
--- a/src/gui/main.cpp
+++ b/src/gui/main.cpp
@@ -43,10 +43,18 @@ void warnSystray()
                           .arg(Theme::instance()->appNameGUI()));
 }
 
+#include "checksums.h"
 int main(int argc, char **argv)
 {
+    QTime t;
+    t.start();
+    QByteArray checksum = ComputeChecksum::computeNow("/Users/guruz/Music/x.mp3", "SHA1");
+    qDebug() << checksum;
+    qDebug() << 1.0*t.elapsed()/1000.0;
+    exit(1);
     Q_INIT_RESOURCE(client);
 
+
 #ifdef Q_OS_WIN
     // If the font size ratio is set on Windows, we need to
     // enable the auto pixelRatio in Qt since we don't

diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp
index 488d04f..0cbec3e 100644
--- a/src/libsync/filesystem.cpp
+++ b/src/libsync/filesystem.cpp
@@ -520,6 +520,40 @@ static QByteArray readToCrypto( const QString& filename, QCryptographicHash::Alg
     return arr;
 }
 
+/*
+#include <openssl/sha.h>
+static QByteArray readToCrypto( const QString& filename, QCryptographicHash::Algorithm algo )
+{
+    QFile file(filename);
+    const qint64 bufSize = qMin(BUFSIZE, file.size() + 1);
+    QByteArray buf(bufSize, Qt::Uninitialized);
+    QByteArray arr;
+    //QCryptographicHash crypto( algo );
+    SHA_CTX ctx;
+    if(!SHA1_Init(&ctx))
+            return QByteArray();
+
+    if (file.open(QIODevice::ReadOnly)) {
+        qDebug() << filename;
+
+        qint64 size;
+        while (!file.atEnd()) {
+            size = file.read( buf.data(), bufSize );
+            if( size > 0 ) {
+                //crypto.addData(buf.data(), size);
+                SHA1_Update(&ctx, (unsigned char*)buf.data(), size);
+            }
+        }
+        //arr = crypto.result().toHex();
+        unsigned char md[SHA_DIGEST_LENGTH];
+        if(!SHA1_Final(md, &ctx))
+                return QByteArray();
+        return QByteArray((const char*)md, SHA_DIGEST_LENGTH).toHex();
+    }
+    return arr;
+}
+*/
+
 QByteArray FileSystem::calcMd5( const QString& filename )
 {
     return readToCrypto( filename, QCryptographicHash::Md5 );

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions