From 3d1ecdbb48a74bc255e01587049e4094ac2e4ba1 Mon Sep 17 00:00:00 2001 From: Olivier Ldff Date: Thu, 5 Sep 2019 17:19:43 +0200 Subject: [PATCH] Benchmark append --- CTestLists.txt | 5 +- .../ObjectListModel/SharedObjectList.hpp | 1 - tests/ObjectListTests.cpp | 18 ++++- tests/SharedObjectListTests.cpp | 66 +++++++++++++++++++ tests/include/{FooTest.hpp => Foo.hpp} | 10 +-- tests/include/FooList.hpp | 12 ++++ tests/include/SharedFooList.hpp | 12 ++++ 7 files changed, 113 insertions(+), 11 deletions(-) rename tests/include/{FooTest.hpp => Foo.hpp} (75%) create mode 100644 tests/include/FooList.hpp create mode 100644 tests/include/SharedFooList.hpp diff --git a/CTestLists.txt b/CTestLists.txt index e71ef50..a50cbf9 100644 --- a/CTestLists.txt +++ b/CTestLists.txt @@ -16,7 +16,10 @@ set(OBJLISTMODEL_TEST_TARGET_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests) set(OBJLISTMODEL_TEST_SRCS ${OBJLISTMODEL_TEST_TARGET_DIR}/Tests.cpp ${OBJLISTMODEL_TEST_TARGET_DIR}/ObjectListTests.cpp ${OBJLISTMODEL_TEST_TARGET_DIR}/SharedObjectListTests.cpp - ${OBJLISTMODEL_TEST_TARGET_DIR}/include/FooTest.hpp + + ${OBJLISTMODEL_TEST_TARGET_DIR}/include/Foo.hpp + ${OBJLISTMODEL_TEST_TARGET_DIR}/include/FooList.hpp + ${OBJLISTMODEL_TEST_TARGET_DIR}/include/SharedFooList.hpp ) message(STATUS "Add Test: ${OBJLISTMODEL_TEST_TARGET}") diff --git a/src/include/ObjectListModel/SharedObjectList.hpp b/src/include/ObjectListModel/SharedObjectList.hpp index 7d874da..ff01842 100644 --- a/src/include/ObjectListModel/SharedObjectList.hpp +++ b/src/include/ObjectListModel/SharedObjectList.hpp @@ -95,7 +95,6 @@ public slots: // virtual methods API for QML virtual QSharedPointer get(const QString & uid) const = 0; virtual QSharedPointer getFirst(void) const = 0; virtual QSharedPointer getLast(void) const = 0; - virtual QVariantList toVarArray(void) const = 0; protected slots: // internal callback virtual void onItemPropertyChanged(void) = 0; diff --git a/tests/ObjectListTests.cpp b/tests/ObjectListTests.cpp index 5c78dd2..517940f 100644 --- a/tests/ObjectListTests.cpp +++ b/tests/ObjectListTests.cpp @@ -1,11 +1,13 @@ // Spy signal call without having a main loop #include +#include +#include // gtest framework #include // Our test classes -#include +#include // First basic test fixture that have only one QObject class ObjectListTest : public ::testing::Test @@ -51,4 +53,18 @@ TEST_F(ObjectListTest, Append) delete foo1; delete foo2; +} + +TEST_F(ObjectListTest, AppendFuzz) +{ + auto initTime = QDateTime::currentMSecsSinceEpoch(); + for(int i = 0; i < 10000; ++i) + _list.append(new Foo()); + auto appendTime = QDateTime::currentMSecsSinceEpoch(); + ASSERT_EQ(_list.size(), 10000); + int i = 0; + _list.clear(); + auto clearTime = QDateTime::currentMSecsSinceEpoch(); + + qDebug("Append 10000 QObject Time : %llu ms. Clear time : %llu ms", (appendTime - initTime), (clearTime - appendTime)); } \ No newline at end of file diff --git a/tests/SharedObjectListTests.cpp b/tests/SharedObjectListTests.cpp index e69de29..3aa0736 100644 --- a/tests/SharedObjectListTests.cpp +++ b/tests/SharedObjectListTests.cpp @@ -0,0 +1,66 @@ +// Spy signal call without having a main loop +#include +#include +#include + +// gtest framework +#include + +// Our test classes +#include + +// First basic test fixture that have only one QObject +class SharedObjectListTest : public ::testing::Test +{ +protected: + void SetUp() override + { + } + + void TearDown() override + { + } + + SharedFooList _list; +}; + +TEST_F(SharedObjectListTest, Append) +{ + QSignalSpy spyAboutToInsert(&_list, &Olm::SharedObjectListBase::itemAboutToBeInserted); + QSignalSpy spyInsert(&_list, &Olm::SharedObjectListBase::itemInserted); + ASSERT_EQ(_list.size(), 0); + + auto foo1 = QSharedPointer(new Foo()); + _list.append(foo1); + + ASSERT_EQ(_list.size(), 1); + ASSERT_EQ(spyAboutToInsert.count(), 1); + ASSERT_EQ(spyInsert.count(), 1); + + auto foo2 = QSharedPointer(new Foo()); + _list.append(foo2); + _list.append(foo1); + + ASSERT_EQ(_list.size(), 3); + ASSERT_EQ(spyAboutToInsert.count(), 3); + ASSERT_EQ(spyInsert.count(), 3); + + ASSERT_TRUE(_list.at(0) == foo1); + ASSERT_TRUE(_list.at(1) == foo2); + ASSERT_TRUE(_list.at(2) == foo1); + + _list.clear(); +} + +TEST_F(SharedObjectListTest, AppendFuzz) +{ + auto initTime = QDateTime::currentMSecsSinceEpoch(); + for(int i = 0; i < 10000; ++i) + _list.append(QSharedPointer(new Foo())); + auto appendTime = QDateTime::currentMSecsSinceEpoch(); + ASSERT_EQ(_list.size(), 10000); + _list.clear(); + auto clearTime = QDateTime::currentMSecsSinceEpoch(); + + qDebug("Append 10000 Shared QObject Time : %llu ms. Clear time : %llu ms", (appendTime - initTime), (clearTime - appendTime)); +} \ No newline at end of file diff --git a/tests/include/FooTest.hpp b/tests/include/Foo.hpp similarity index 75% rename from tests/include/FooTest.hpp rename to tests/include/Foo.hpp index 2a8c19b..b2d1b7b 100644 --- a/tests/include/FooTest.hpp +++ b/tests/include/Foo.hpp @@ -1,8 +1,7 @@ -#ifndef __FOO_TEST_HPP__ -#define __FOO_TEST_HPP__ +#ifndef __FOO_HPP__ +#define __FOO_HPP__ #include -#include class Foo : public QObject { @@ -26,9 +25,4 @@ class Foo : public QObject void fooChanged(); }; -class FooList : public Olm::ObjectList -{ - Q_OBJECT -}; - #endif \ No newline at end of file diff --git a/tests/include/FooList.hpp b/tests/include/FooList.hpp new file mode 100644 index 0000000..0828fa8 --- /dev/null +++ b/tests/include/FooList.hpp @@ -0,0 +1,12 @@ +#ifndef __FOO_LIST_HPP__ +#define __FOO_LIST_HPP__ + +#include +#include + +class FooList : public Olm::ObjectList +{ + Q_OBJECT +}; + +#endif \ No newline at end of file diff --git a/tests/include/SharedFooList.hpp b/tests/include/SharedFooList.hpp new file mode 100644 index 0000000..a61a9e6 --- /dev/null +++ b/tests/include/SharedFooList.hpp @@ -0,0 +1,12 @@ +#ifndef __SHARED_FOO_LIST_HPP__ +#define __SHARED_FOO_LIST_HPP__ + +#include +#include + +class SharedFooList : public Olm::SharedObjectList +{ + Q_OBJECT +}; + +#endif \ No newline at end of file