Browse Source

Cleaned up performance testing

Template for performance tisting in DebugWidget, on_debugPushButton_clicked.
Felix Turo 4 years ago
parent
commit
53cdae6241

+ 1 - 0
mainwindow.cpp

@@ -23,6 +23,7 @@ MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
     , ui(new Ui::MainWindow)
 {
+    ATimer timer(this);
     ui->setupUi(this);
 
     // Set up Toolbar

+ 1 - 0
mainwindow.h

@@ -37,6 +37,7 @@
 #include "src/gui/dialogues/newpilotdialog.h"
 #include "src/classes/arunguard.h"
 #include "src/experimental/adatabase.h"
+#include "src/testing/atimer.h"
 
 QT_BEGIN_NAMESPACE
 namespace Ui {

+ 28 - 2
src/gui/widgets/debugwidget.cpp

@@ -1,6 +1,6 @@
 #include "debugwidget.h"
 #include "ui_debugwidget.h"
-#include "src/testing/adebug.h"
+
 
 
 DebugWidget::DebugWidget(QWidget *parent) :
@@ -23,6 +23,7 @@ DebugWidget::~DebugWidget()
 
 void DebugWidget::on_resetUserTablesPushButton_clicked()
 {
+    ATimer timer(this);
     QMessageBox result;
     if (ADataBaseSetup::resetToDefault()){
         result.setText("Database successfully reset.\n\nRestarting app.");
@@ -33,11 +34,11 @@ void DebugWidget::on_resetUserTablesPushButton_clicked()
         result.setText("Errors have occurred. Check console for Debug output. ");
         result.exec();
     }
-
 }
 
 void DebugWidget::on_resetDatabasePushButton_clicked()
 {
+    ATimer timer(this);
     QMessageBox mb(this);
     //check if template dir exists and create if needed.
     QDir dir("data/templates");
@@ -89,6 +90,7 @@ void DebugWidget::downloadFinished()
 
 void DebugWidget::on_fillUserDataPushButton_clicked()
 {
+    ATimer timer(this);
     QMessageBox mb(this);
     //check if template dir exists and create if needed.
     QDir dir("data/templates");
@@ -138,6 +140,7 @@ void DebugWidget::on_selectCsvPushButton_clicked()
 
 void DebugWidget::on_importCsvPushButton_clicked()
 {
+    ATimer timer(this);
     auto file = QFileInfo(ui->importCsvLineEdit->text());
     DEB("File exists/is file: " << file.exists() << file.isFile() << " Path: " << file.absoluteFilePath());
 
@@ -161,5 +164,28 @@ void DebugWidget::on_importCsvPushButton_clicked()
 
 void DebugWidget::on_debugPushButton_clicked()
 {
+    qlonglong number_of_runs = 5000;
+    long time1 = 0;
+    long time2 = 0;
+    using namespace experimental;
+    {
+
+        ATimer timer;
+        for (int i = 0; i < number_of_runs; i++) {
+            // first block, do stuff here...
+            aDB()->getEntry({"pilots", i});
+        }
 
+        time1 = timer.timeNow();
+    }
+    {
+        ATimer timer;
+        for (int i = 0; i < number_of_runs; i++) {
+            // second block, do stuff here...
+            aDB()->getPilotEntry(i);
+        }
+        time2 = timer.timeNow();
+    }
+    DEB("First block executed " << number_of_runs << " times for a total of " << time1 << " milliseconds.");
+    DEB("Second block executed " << number_of_runs << " times for a total of " << time2 << " milliseconds.");
 }

+ 8 - 0
src/gui/widgets/debugwidget.h

@@ -14,6 +14,14 @@
 #include "src/classes/adownload.h"
 #include "src/functions/areadcsv.h"
 
+#include "src/experimental/adatabase.h"
+#include "src/experimental/aentry.h"
+#include "src/experimental/apilotentry.h"
+
+#include "src/testing/abenchmark.h"
+#include "src/testing/atimer.h"
+#include "src/testing/adebug.h"
+
 namespace Ui {
 class DebugWidget;
 }

+ 5 - 0
src/testing/abenchmark.h

@@ -20,6 +20,9 @@
 
 #include <QObject>
 #include "src/testing/adebug.h"
+#include "src/experimental/adatabase.h"
+#include "src/experimental/aentry.h"
+#include "src/experimental/decl.h"
 
 /*!
  * \brief The ABenchmark class provides quick access to benchmarking two functions for
@@ -35,6 +38,8 @@ public:
 
     ABenchmark(bool (*function_one)(), bool (*function_two)(), int number_of_runs);
 
+    //ABenchmark(experimental::AEntry (*function_one)(experimental::DataPosition), experimental::AEntry (*function_two)(int), int number_of_runs);
+
 };
 
 #endif // ABENCHMARK_H

+ 12 - 11
src/testing/atimer.cpp

@@ -22,9 +22,9 @@ ATimer::ATimer(QObject *parent) : QObject(parent)
 {
      start = std::chrono::high_resolution_clock::now();
      if(parent == nullptr) {
-         qDebug() << "Starting Timer... ";
+         DEB("Starting Timer... ");
      } else {
-         qDebug() << "Starting Timer for: " << parent->objectName();
+         DEB("Starting Timer for: " << parent->objectName());
      }
 
 }
@@ -33,26 +33,27 @@ ATimer::~ATimer()
 {
     stop = std::chrono::high_resolution_clock::now();
     if(parent() == nullptr) {
-        qDebug() << "Execution time: "
+        DEB("Execution time: "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count()
-                 << "milliseconds.";
+                 << "milliseconds.");
     } else {
-        qDebug() << "Execution time for: " << parent()->objectName() << ": "
+        DEB("Execution time for: " << parent()->objectName() << ": "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count()
-                 << "milliseconds.";
+                 << "milliseconds.");
     }
 }
 
-void ATimer::timeNow()
+long ATimer::timeNow()
 {
     intermediate_point = std::chrono::high_resolution_clock::now();
     if(parent() == nullptr) {
-        qDebug() << "Intermediate time: "
+        DEB("Intermediate time: "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(intermediate_point - start).count()
-                 << "milliseconds.";
+                 << "milliseconds.");
     } else {
-        qDebug() << "Intermediate time for: " << parent()->objectName() << ": "
+        DEB("Intermediate time for: " << parent()->objectName() << ": "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(intermediate_point - start).count()
-                 << "milliseconds.";
+                 << "milliseconds.");
     }
+    return std::chrono::duration_cast<std::chrono::milliseconds>(intermediate_point - start).count();
 }

+ 5 - 1
src/testing/atimer.h

@@ -21,6 +21,7 @@
 #include <QObject>
 #include <chrono>
 #include <QDebug>
+#include "src/testing/adebug.h"
 
 /*!
  * \brief The ATimer class provides an easy to use performance timer.
@@ -38,7 +39,10 @@ public:
     ATimer(QObject* parent = nullptr);
     ~ATimer();
 
-    void timeNow();
+    /*!
+     * \brief timeNow takes an intermediate timing and returns miliseconds elapsed.
+     */
+    long timeNow();
 private:
 
     std::chrono::high_resolution_clock::time_point start;