2016-05-24 14:47:37 +08:00
|
|
|
#include <QtTest>
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QSqlError>
|
|
|
|
|
|
2016-05-24 14:53:40 +08:00
|
|
|
#include "consts.h"
|
|
|
|
|
|
2019-07-21 23:33:06 +08:00
|
|
|
#include "tst_benchmark.h"
|
2016-05-24 14:47:37 +08:00
|
|
|
#include "query.h"
|
|
|
|
|
#include "tableset.h"
|
|
|
|
|
#include "tablemodel.h"
|
|
|
|
|
#include "databasemodel.h"
|
|
|
|
|
|
2019-02-08 17:11:53 +08:00
|
|
|
#include "user.h"
|
2016-05-24 14:47:37 +08:00
|
|
|
#include "post.h"
|
|
|
|
|
#include "comment.h"
|
2019-02-08 17:11:53 +08:00
|
|
|
#include "score.h"
|
2016-05-24 14:47:37 +08:00
|
|
|
|
2019-02-10 22:27:29 +08:00
|
|
|
BenchmarkTest::BenchmarkTest(QObject *parent) : QObject(parent)
|
2016-05-24 14:47:37 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-10 22:27:29 +08:00
|
|
|
void BenchmarkTest::initTestCase()
|
2016-05-24 14:47:37 +08:00
|
|
|
{
|
2019-02-08 17:11:53 +08:00
|
|
|
REGISTER(User);
|
|
|
|
|
REGISTER(Post);
|
|
|
|
|
REGISTER(Score);
|
|
|
|
|
REGISTER(Comment);
|
|
|
|
|
REGISTER(WeblogDatabase);
|
2016-05-24 14:47:37 +08:00
|
|
|
|
2016-05-24 14:53:40 +08:00
|
|
|
db.setDriver(DRIVER);
|
|
|
|
|
db.setHostName(HOST);
|
2019-07-22 22:04:13 +08:00
|
|
|
db.setDatabaseName(DATABASE);
|
2016-05-24 14:53:40 +08:00
|
|
|
db.setUserName(USERNAME);
|
|
|
|
|
db.setPassword(PASSWORD);
|
2016-05-24 14:47:37 +08:00
|
|
|
|
|
|
|
|
bool ok = db.open();
|
|
|
|
|
|
|
|
|
|
QTEST_ASSERT(ok);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-10 22:27:29 +08:00
|
|
|
void BenchmarkTest::insert1kPost()
|
2016-05-24 14:47:37 +08:00
|
|
|
{
|
|
|
|
|
QTime t;
|
|
|
|
|
t.start();
|
|
|
|
|
|
2019-02-08 17:26:26 +08:00
|
|
|
for (int i = 0; i < 100; ++i) {
|
2019-06-18 23:37:03 +08:00
|
|
|
auto newPost = Nut::create<Post>();
|
2016-05-24 14:47:37 +08:00
|
|
|
newPost->setTitle("post title");
|
|
|
|
|
newPost->setSaveDate(QDateTime::currentDateTime());
|
|
|
|
|
|
|
|
|
|
db.posts()->append(newPost);
|
|
|
|
|
}
|
|
|
|
|
db.saveChanges();
|
2019-02-10 17:35:35 +08:00
|
|
|
qDebug("1k post inserted in %d ms", t.elapsed());
|
2016-05-24 14:47:37 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-10 22:27:29 +08:00
|
|
|
QTEST_MAIN(BenchmarkTest)
|