From d1bdbc2741e44e62002917d45858651f815e45f6 Mon Sep 17 00:00:00 2001 From: garak Date: Tue, 22 Nov 2022 21:12:56 -0500 Subject: [PATCH] create temporary timing function --- include/mainwindow.h | 8 ++++++ src/mainwindow.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/include/mainwindow.h b/include/mainwindow.h index 87ea30aa..e3b39e83 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -390,6 +390,14 @@ private: QObjectList shortcutableObjects() const; void addCustomHeaderValue(QString key, QJsonValue value, bool isNew = false); int insertTilesetLabel(QStringList * list, QString label); + + // TODO: remove + void runSpeedTest(); + struct SpeedTestStruct { + qint64 openProject; + qint64 setMap; + qint64 saveAll; + }; }; enum MapListUserRoles { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 10a38b6d..47b17db9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -119,6 +119,9 @@ void MainWindow::initShortcuts() { shortcutsConfig.load(); shortcutsConfig.setDefaultShortcuts(shortcutableObjects()); applyUserShortcuts(); + + // TODO: remove + auto *s = new QShortcut(QKeySequence("Ctrl+R"), this, [this](){runSpeedTest();}); } void MainWindow::initExtraShortcuts() { @@ -2864,3 +2867,65 @@ void MainWindow::closeEvent(QCloseEvent *event) { QMainWindow::closeEvent(event); } + +#include +void MainWindow::runSpeedTest() { + // 10 iterations of this function: + // 1 - load project + // 2 - switch map + // 3 - save all + + if (!editor || !editor->project) return; + + const int runs = 10; + QElapsedTimer timer; + + QList times; + + timer.start(); + for (int i = 0; i < runs; i++) { + struct SpeedTestStruct benchmarks; + setMap("SlateportCity"); // reset map + timer.restart(); + + // 1 - load project + openProject(editor->project->root); + benchmarks.openProject = timer.restart(); + + // 2 - switch maps + setMap("LilycoveCity"); + benchmarks.setMap = timer.restart(); + + // 3 - save all + editor->saveProject(); + benchmarks.saveAll = timer.restart(); + + // add time to list + times.append(benchmarks); + } + + // summary + qint64 min = std::numeric_limits::max(), max = 0, avg = 0; + QString summary = QString("RUN LOAD SWAP SAVE TOT \n"); + for (int i = 0; i < runs; i++) { + summary += QString::number(i+1).leftJustified(6, ' '); + qint64 open = times[i].openProject; + summary += QString::number(open).leftJustified(6, ' '); + qint64 swap = times[i].setMap; + summary += QString::number(swap).leftJustified(6, ' '); + qint64 save = times[i].saveAll; + summary += QString::number(save).leftJustified(6, ' '); + qint64 tot = open + swap + save; + summary += QString::number(tot).leftJustified(6, ' '); + summary += "\n"; + + if (tot < min) min = tot; + if (tot > max) max = tot; + avg += tot; + } + avg /= runs; + + summary += "MIN: " + QString::number(min).leftJustified(6, ' ') + "MAX: " + QString::number(max).leftJustified(6, ' ') + "AVG: " + QString::number(avg) + "\n"; + + qDebug() << qUtf8Printable(summary); +}