Commit b928488a authored by Dario Freddi's avatar Dario Freddi

Updating the benchmark. Turns out using QtConcurrent saves ~30% of the time...

Updating the benchmark. Turns out using QtConcurrent saves ~30% of the time when querying multiple databases. ~300ms to query and create 9000 packages, that's rocking
Signed-off-by: default avatarDario Freddi <drf@kde.org>
parent 3c3d849c
......@@ -22,8 +22,10 @@ operations/akabeiplaininstalloperation.cpp
qt4_automoc(${AKABEI_CORE_SRCS})
qt4_automoc(${AKABEI_OPERATION_SRCS})
# There are some files which are not detected by automoc, add them
qt4_wrap_cpp(AKABEI_MISSING_MOCS akabeibackend_p.h)
add_library(akabeicore SHARED ${AKABEI_CORE_SRCS} ${AKABEI_OPERATION_SRCS})
add_library(akabeicore SHARED ${AKABEI_CORE_SRCS} ${AKABEI_OPERATION_SRCS} ${AKABEI_MISSING_MOCS})
set_target_properties(akabeicore PROPERTIES VERSION ${MAJOR_AKABEI_VERSION}.${MINOR_AKABEI_VERSION}.${PATCH_AKABEI_VERSION}
SOVERSION ${MAJOR_AKABEI_VERSION}
......
......@@ -173,6 +173,8 @@ void BackendPrivate::packageQueryFinished()
{
Q_Q(Backend);
qDebug() << "A query is over";
QUuid uuid = QUuid(sender()->property("__Akabei_Query_Uuid").toString());
if (!queryPackageFuturePool.contains(uuid)) {
qWarning() << "No such UUID registered!";
......@@ -187,6 +189,7 @@ void BackendPrivate::packageQueryFinished()
retlist << *i;
}
qDebug() << "Emitting the signal";
emit q->queryPackagesCompleted(uuid, retlist);
}
......@@ -329,6 +332,8 @@ QUuid Backend::queryGroups(const QString& sql)
QFuture< QList< Group* > > future = QtConcurrent::mapped(allDbs, ConcurrentGroupQuery(sql));
watcher->setFuture(future);
return uuid;
}
QUuid Backend::queryPackages(const QString& sql)
......@@ -347,6 +352,8 @@ QUuid Backend::queryPackages(const QString& sql)
QFuture< QList< Package* > > future = QtConcurrent::mapped(allDbs, ConcurrentPackageQuery(sql));
watcher->setFuture(future);
return uuid;
}
QUuid Backend::searchGroups(const QString& token)
......
......@@ -58,8 +58,8 @@ class AKABEICORESHARED_EXPORT Backend : public QObject
Q_SIGNALS:
void statusChanged(Akabei::Backend::Status status);
void queryPackagesCompleted(const QUuid &id, const QList<Package*> &result);
void queryGroupCompleted(const QUuid &id, const QList<Group*> &result);
void queryPackagesCompleted(const QUuid &id, const QList<Akabei::Package*> &result);
void queryGroupCompleted(const QUuid &id, const QList<Akabei::Group*> &result);
private:
Backend(QObject* parent = 0);
......
......@@ -37,6 +37,7 @@ class GroupPool
class BackendPrivate : public QObject
{
Q_OBJECT
Q_DECLARE_PUBLIC(Backend)
Backend * const q_ptr;
......
......@@ -5,10 +5,12 @@
#include "akabeiconfig.h"
#include "akabeibackend.h"
void DatabaseBenchmark::benchmark_createDatabase()
void DatabaseBenchmark::benchmark_start()
{
Akabei::Config::instance()->setDatabasePath("/home/kde-devel");
Akabei::Config::instance()->setDatabases(QStringList() << "test1" << "test2");
QBENCHMARK_ONCE {
QEventLoop e;
connect(Akabei::Backend::instance(), SIGNAL(statusChanged(Akabei::Backend::Status)), &e, SLOT(quit()));
......@@ -17,22 +19,38 @@ void DatabaseBenchmark::benchmark_createDatabase()
}
QVERIFY(Akabei::Backend::instance()->status() == Akabei::Backend::StatusReady);
}
db = Akabei::Backend::instance()->localDatabase();
void DatabaseBenchmark::benchmark_QueryGroups()
{
GroupEventLoop e;
connect(Akabei::Backend::instance(), SIGNAL(queryGroupCompleted(QUuid,QList<Akabei::Group*>)),
&e, SLOT(requestQuit(QUuid,QList<Akabei::Group*>)));
qDebug() << db->groups().size() << "groups handled";
QBENCHMARK_ONCE {
e.setUuid(Akabei::Backend::instance()->groups());
qDebug() << "Begin loop execution";
e.exec();
}
//qDebug() << packages.first()->name() << packages.first()->databaseId();
qDebug() << "Retrieved and created " << e.result().size() << "groups";
}
void DatabaseBenchmark::benchmark_QueryDatabase()
void DatabaseBenchmark::benchmark_QueryPackages()
{
QList<Akabei::Package*> packages;
PackageEventLoop e;
connect(Akabei::Backend::instance(), SIGNAL(queryPackagesCompleted(QUuid,QList<Akabei::Package*>)),
&e, SLOT(requestQuit(QUuid,QList<Akabei::Package*>)));
QBENCHMARK_ONCE {
packages = db->packages();
e.setUuid(Akabei::Backend::instance()->packages());
qDebug() << "Begin loop execution";
e.exec();
}
//qDebug() << packages.first()->name() << packages.first()->databaseId();
qDebug() << "Retrieved and created " << packages.count() << "packages";
qDebug() << "Retrieved and created " << e.result().size() << "packages";
}
QTEST_MAIN(DatabaseBenchmark)
......@@ -4,19 +4,76 @@
#include <QtTest/QtTest>
namespace Akabei {
class Database;
class Group;
class Package;
}
class DatabaseBenchmark : public QObject
{
Q_OBJECT
private slots:
void benchmark_createDatabase();
void benchmark_QueryDatabase();
void benchmark_start();
void benchmark_QueryGroups();
void benchmark_QueryPackages();
};
class GroupEventLoop : public QEventLoop
{
Q_OBJECT
public:
GroupEventLoop(QObject *parent = 0) : QEventLoop(parent) {}
virtual ~GroupEventLoop() {}
void setUuid(const QUuid &uuid) {
m_uuid = uuid;
}
QList<Akabei::Group*> result() const {
return m_result;
}
public slots:
void requestQuit(const QUuid &uuid, const QList<Akabei::Group*> &result) {
qDebug() << "Request quit";
if (uuid == m_uuid) {
m_result = result;
quit();
}
}
private:
Akabei::Database *db;
QUuid m_uuid;
QList<Akabei::Group*> m_result;
};
class PackageEventLoop : public QEventLoop
{
Q_OBJECT
public:
PackageEventLoop(QObject *parent = 0) : QEventLoop(parent) {}
virtual ~PackageEventLoop() {}
void setUuid(const QUuid &uuid) {
m_uuid = uuid;
}
QList<Akabei::Package*> result() const {
return m_result;
}
public slots:
void requestQuit(const QUuid &uuid, const QList<Akabei::Package*> &result) {
qDebug() << "Request quit" << uuid << m_uuid;
if (uuid == m_uuid) {
m_result = result;
quit();
}
}
private:
QUuid m_uuid;
QList<Akabei::Package*> m_result;
};
#endif // DATABASEBENCHMARK_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment