[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [baloo] autotests: Benchmark for PositionCodec::encode()
From:       Christian Ehrlicher <Ch.Ehrlicher () gmx ! de>
Date:       2016-11-05 11:33:02
Message-ID: E1c2zDa-000438-Kh () code ! kde ! org
[Download RAW message or body]

Git commit 8ca69dcb32a38027f4ec319ae112ca382b145733 by Christian Ehrlicher.
Committed on 05/11/2016 at 11:32.
Pushed by chehrlic into branch 'master'.

Benchmark for PositionCodec::encode()
REVIEW: 129185

M  +51   -9    autotests/benchmarks/positioncodecbenchmark.cpp
M  +1    -0    autotests/unit/codecs/CMakeLists.txt
A  +71   -0    autotests/unit/codecs/positioncodectest.cpp     [License: LGPL]

http://commits.kde.org/baloo/8ca69dcb32a38027f4ec319ae112ca382b145733

diff --git a/autotests/benchmarks/positioncodecbenchmark.cpp \
b/autotests/benchmarks/positioncodecbenchmark.cpp index e7aeebf..07440d7 100644
--- a/autotests/benchmarks/positioncodecbenchmark.cpp
+++ b/autotests/benchmarks/positioncodecbenchmark.cpp
@@ -30,26 +30,68 @@ class PositionCodecBenchmark : public QObject
 {
     Q_OBJECT
 private Q_SLOTS:
-    void test();
+    void initTestCase();
+    // data 1 - a lot of positions, small amount of PositionInfo
+    void benchEncodeData1();
+    void benchDecodeData1();
+    // data 2 - few positions, large amount of PositionInfo
+    void benchEncodeData2();
+    void benchDecodeData2();
+private:
+    QVector<PositionInfo> m_benchmarkData1;
+    QVector<PositionInfo> m_benchmarkData2;
 };
 
-void PositionCodecBenchmark::test()
+void PositionCodecBenchmark::initTestCase()
 {
-    PositionCodec codec;
+    m_benchmarkData1.clear();
+    m_benchmarkData1.reserve(100);
+    for(int i = 0; i < 100; ++i)
+    {
+        PositionInfo info;
+        info.docId = (i + 1) * 4711;
+        info.positions.reserve(3000);
+        for (int j = 0; j < 3000; j++)
+            info.positions.append(((j + 1) * 42) / info.docId);
+        m_benchmarkData1.append(info);
+    }
 
-    QVector<PositionInfo> vec;
+    m_benchmarkData2.clear();
+    m_benchmarkData2.reserve(5000);
     for (int i = 0; i < 5000; i++) {
         PositionInfo info;
         info.docId = i;
         info.positions = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
 
-        vec << info;
+        m_benchmarkData2.append(info);
     }
 
-    QBENCHMARK {
-        QByteArray data = codec.encode(vec);
-        codec.decode(data);
-    }
+}
+
+void PositionCodecBenchmark::benchEncodeData1()
+{
+    PositionCodec pc;
+    QBENCHMARK { pc.encode(m_benchmarkData1); }
+}
+
+void PositionCodecBenchmark::benchDecodeData1()
+{
+    PositionCodec pc;
+    const QByteArray ba = pc.encode(m_benchmarkData1);
+    QBENCHMARK { pc.decode(ba); }
+}
+
+void PositionCodecBenchmark::benchEncodeData2()
+{
+    PositionCodec pc;
+    QBENCHMARK { pc.encode(m_benchmarkData2); }
+}
+
+void PositionCodecBenchmark::benchDecodeData2()
+{
+    PositionCodec pc;
+    const QByteArray ba = pc.encode(m_benchmarkData2);
+    QBENCHMARK { pc.decode(ba); }
 }
 
 QTEST_MAIN(PositionCodecBenchmark)
diff --git a/autotests/unit/codecs/CMakeLists.txt \
b/autotests/unit/codecs/CMakeLists.txt index f65d633..834b467 100644
--- a/autotests/unit/codecs/CMakeLists.txt
+++ b/autotests/unit/codecs/CMakeLists.txt
@@ -10,4 +10,5 @@ ENDMACRO()
 baloo_codecs_auto_tests(
     doctermscodectest
     postingcodectest
+    positioncodectest
 )
diff --git a/autotests/unit/codecs/positioncodectest.cpp \
b/autotests/unit/codecs/positioncodectest.cpp new file mode 100644
index 0000000..5c0a5e1
--- /dev/null
+++ b/autotests/unit/codecs/positioncodectest.cpp
@@ -0,0 +1,71 @@
+/*
+   This file is part of the KDE Baloo project.
+   Copyright (C) 2016 Christian Ehrlicher <ch.ehrlicher@gmx.de>
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) version 3, or any
+   later version accepted by the membership of KDE e.V. (or its
+   successor approved by the membership of KDE e.V.), which shall
+   act as a proxy defined in Section 6 of version 3 of the license.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <QCryptographicHash>
+#include <QtTest>
+#include "positioncodec.h"
+#include "positioninfo.h"
+
+using namespace Baloo;
+
+class PositionCodecTest : public QObject
+{
+Q_OBJECT
+public:
+    PositionCodecTest() = default;
+    ~PositionCodecTest() = default;
+private Q_SLOTS:
+    void initTestCase();
+    void checkEncodeOutput();
+private:
+    QVector<PositionInfo> m_data;
+};
+
+QTEST_MAIN ( PositionCodecTest )
+
+void PositionCodecTest::initTestCase()
+{
+    m_data.clear();
+    m_data.reserve(100);
+    for(int i = 0; i < 100; ++i)
+    {
+        PositionInfo info;
+        info.docId = (i + 1) * 4711;
+        info.positions.reserve(3000);
+        for (int j = 0; j < 3000; j++)
+            info.positions.append(((j + 1) * 42) / info.docId);
+        m_data.append(info);
+    }
+}
+
+void PositionCodecTest::checkEncodeOutput()
+{
+    PositionCodec pc;
+    const QByteArray ba = pc.encode(m_data);
+    QCOMPARE(ba.size(), 301000);
+    const QByteArray md5 = QCryptographicHash::hash(ba, \
QCryptographicHash::Md5).toHex(); +    QCOMPARE(md5, \
QByteArray("d44a606d301937bef105411c0ee77a88")); +    // and now decode the whole \
stuff +    QVector<PositionInfo> decodedData = pc.decode(ba);
+    QCOMPARE(m_data, decodedData);
+}
+
+#include "positioncodectest.moc"


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic