Skip to content

Commit

Permalink
Benchmark append
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierLDff committed Sep 5, 2019
1 parent 14e6fff commit 3d1ecdb
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 11 deletions.
5 changes: 4 additions & 1 deletion CTestLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
1 change: 0 additions & 1 deletion src/include/ObjectListModel/SharedObjectList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public slots: // virtual methods API for QML
virtual QSharedPointer<QObject> get(const QString & uid) const = 0;
virtual QSharedPointer<QObject> getFirst(void) const = 0;
virtual QSharedPointer<QObject> getLast(void) const = 0;
virtual QVariantList toVarArray(void) const = 0;

protected slots: // internal callback
virtual void onItemPropertyChanged(void) = 0;
Expand Down
18 changes: 17 additions & 1 deletion tests/ObjectListTests.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Spy signal call without having a main loop
#include <QSignalSpy>
#include <QDateTime>
#include <QDebug>

// gtest framework
#include <gtest/gtest.h>

// Our test classes
#include <FooTest.hpp>
#include <FooList.hpp>

// First basic test fixture that have only one QObject
class ObjectListTest : public ::testing::Test
Expand Down Expand Up @@ -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));
}
66 changes: 66 additions & 0 deletions tests/SharedObjectListTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Spy signal call without having a main loop
#include <QSignalSpy>
#include <QDateTime>
#include <QDebug>

// gtest framework
#include <gtest/gtest.h>

// Our test classes
#include <SharedFooList.hpp>

// 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<Foo>(new Foo());
_list.append(foo1);

ASSERT_EQ(_list.size(), 1);
ASSERT_EQ(spyAboutToInsert.count(), 1);
ASSERT_EQ(spyInsert.count(), 1);

auto foo2 = QSharedPointer<Foo>(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<Foo>(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));
}
10 changes: 2 additions & 8 deletions tests/include/FooTest.hpp → tests/include/Foo.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef __FOO_TEST_HPP__
#define __FOO_TEST_HPP__
#ifndef __FOO_HPP__
#define __FOO_HPP__

#include <QObject>
#include <ObjectListModel.hpp>

class Foo : public QObject
{
Expand All @@ -26,9 +25,4 @@ class Foo : public QObject
void fooChanged();
};

class FooList : public Olm::ObjectList<Foo>
{
Q_OBJECT
};

#endif
12 changes: 12 additions & 0 deletions tests/include/FooList.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __FOO_LIST_HPP__
#define __FOO_LIST_HPP__

#include <ObjectListModel.hpp>
#include <Foo.hpp>

class FooList : public Olm::ObjectList<Foo>
{
Q_OBJECT
};

#endif
12 changes: 12 additions & 0 deletions tests/include/SharedFooList.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __SHARED_FOO_LIST_HPP__
#define __SHARED_FOO_LIST_HPP__

#include <ObjectListModel.hpp>
#include <Foo.hpp>

class SharedFooList : public Olm::SharedObjectList<Foo>
{
Q_OBJECT
};

#endif

0 comments on commit 3d1ecdb

Please sign in to comment.