|
|
@@ -0,0 +1,150 @@
|
|
|
+#include "benchmarkviewmodel.h"
|
|
|
+
|
|
|
+#include <QElapsedTimer>
|
|
|
+#include <QEventLoop>
|
|
|
+
|
|
|
+#include "models/basemodel.h"
|
|
|
+
|
|
|
+BenchmarkViewModel::BenchmarkViewModel(QObject *parent) : QObject{parent}
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+void BenchmarkViewModel::startBenchmark()
|
|
|
+{
|
|
|
+ setInProgress(true);
|
|
|
+ submitBenchmark();
|
|
|
+ receiveAndDeleteBenchmark();
|
|
|
+ setInProgress(false);
|
|
|
+}
|
|
|
+
|
|
|
+int BenchmarkViewModel::itemsCount() const
|
|
|
+{
|
|
|
+ return m_itemsCount;
|
|
|
+}
|
|
|
+
|
|
|
+void BenchmarkViewModel::setItemsCount(int newItemsCount)
|
|
|
+{
|
|
|
+ if (m_itemsCount == newItemsCount) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_itemsCount = newItemsCount;
|
|
|
+ emit itemsCountChanged();
|
|
|
+}
|
|
|
+
|
|
|
+quint64 BenchmarkViewModel::submitTime() const
|
|
|
+{
|
|
|
+ return m_submitTime;
|
|
|
+}
|
|
|
+
|
|
|
+void BenchmarkViewModel::setSubmitTime(quint64 newSubmitTime)
|
|
|
+{
|
|
|
+ if (m_submitTime == newSubmitTime) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_submitTime = newSubmitTime;
|
|
|
+ emit submitTimeChanged();
|
|
|
+}
|
|
|
+
|
|
|
+quint64 BenchmarkViewModel::receiveTime() const
|
|
|
+{
|
|
|
+ return m_receiveTime;
|
|
|
+}
|
|
|
+
|
|
|
+void BenchmarkViewModel::setReceiveTime(quint64 newReceiveTime)
|
|
|
+{
|
|
|
+ if (m_receiveTime == newReceiveTime) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_receiveTime = newReceiveTime;
|
|
|
+ emit receiveTimeChanged();
|
|
|
+}
|
|
|
+
|
|
|
+quint64 BenchmarkViewModel::removeTime() const
|
|
|
+{
|
|
|
+ return m_removeTime;
|
|
|
+}
|
|
|
+
|
|
|
+void BenchmarkViewModel::setRemoveTime(quint64 newRemoveTime)
|
|
|
+{
|
|
|
+ if (m_removeTime == newRemoveTime) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_removeTime = newRemoveTime;
|
|
|
+ emit removeTimeChanged();
|
|
|
+}
|
|
|
+
|
|
|
+void BenchmarkViewModel::submitBenchmark()
|
|
|
+{
|
|
|
+ BaseModel benchModel("benchmark");
|
|
|
+
|
|
|
+ QEventLoop loop;
|
|
|
+ int callCount = m_itemsCount;
|
|
|
+ connect(&benchModel, &BaseModel::dataChanged, this, [&loop, &callCount] {
|
|
|
+ if (--callCount == 0) {
|
|
|
+ loop.quit();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ QElapsedTimer timer;
|
|
|
+ timer.start();
|
|
|
+ for (int i = 0; i < m_itemsCount; ++i) {
|
|
|
+ benchModel.submitItem(QVariantMap {{ "name", QString("Item %1").arg(i) }});
|
|
|
+ }
|
|
|
+
|
|
|
+ loop.exec();
|
|
|
+ setSubmitTime(timer.elapsed());
|
|
|
+}
|
|
|
+
|
|
|
+void BenchmarkViewModel::receiveAndDeleteBenchmark()
|
|
|
+{
|
|
|
+ QEventLoop loop;
|
|
|
+ QElapsedTimer timer;
|
|
|
+ timer.start();
|
|
|
+ BaseModel benchModel("benchmark");
|
|
|
+ connect(&benchModel, &BaseModel::dataChanged, this, [&loop]() {
|
|
|
+ loop.quit();
|
|
|
+ });
|
|
|
+
|
|
|
+ loop.exec();
|
|
|
+ setReceiveTime(timer.elapsed());
|
|
|
+
|
|
|
+ disconnect(&benchModel, &BaseModel::dataChanged, this, nullptr);
|
|
|
+
|
|
|
+ QStringList itemIdList;
|
|
|
+ for (const QVariant &item : benchModel.items()) {
|
|
|
+ itemIdList << item.toMap().value("id").toString();
|
|
|
+ }
|
|
|
+ int callCount = itemIdList.count();
|
|
|
+ connect(&benchModel, &BaseModel::dataChanged, this, [&loop, &callCount]() {
|
|
|
+ if (--callCount == 0) {
|
|
|
+ loop.quit();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ timer.restart();
|
|
|
+ for (const QString &itemId : itemIdList) {
|
|
|
+ benchModel.deleteItem(itemId);
|
|
|
+ }
|
|
|
+
|
|
|
+ loop.exec();
|
|
|
+ setRemoveTime(timer.elapsed());
|
|
|
+}
|
|
|
+
|
|
|
+bool BenchmarkViewModel::inProgress() const
|
|
|
+{
|
|
|
+ return m_inProgress;
|
|
|
+}
|
|
|
+
|
|
|
+void BenchmarkViewModel::setInProgress(bool newInProgress)
|
|
|
+{
|
|
|
+ if (m_inProgress == newInProgress) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_inProgress = newInProgress;
|
|
|
+ emit inProgressChanged();
|
|
|
+}
|