-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperformancetimer.cpp
48 lines (39 loc) · 1.33 KB
/
performancetimer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "performancetimer.h"
#include <QDateTime>
#include <qdebug.h>
PerformanceTimer::PerformanceTimer(){
}
void PerformanceTimer::start(){
Startpoint = QDateTime::currentMSecsSinceEpoch();
}
void PerformanceTimer::stop(){
qint64 Endpoint = QDateTime::currentMSecsSinceEpoch();
difference = Endpoint - Startpoint;
Print();
}
bool PerformanceTimer::test(unsigned int runs){
if(test_index == 0) start();
else{
double test_diff = QDateTime::currentMSecsSinceEpoch() - test_last_point;
if(test_highest_diff < test_diff ){
test_highest_diff = test_diff;
test_highest_diff_index = test_index;
}
}
test_last_point = QDateTime::currentMSecsSinceEpoch();
if(test_index >= runs - 1){
stop();
qDebug() << "Runs:" << test_index + 1 << "Average:" << difference / (test_index + 1) << "ms" << "Longest Run" << test_highest_diff_index << ":" <<test_highest_diff << "ms";
test_index = 0;
return false;
}
test_index++;
return true;
}
void PerformanceTimer::Print(){
unsigned int sec = difference / 1000;
unsigned int min = sec / 60;
unsigned int hour = min / 60;
unsigned int day = hour / 24;
qDebug() << "Total Time: " << day << "d " << hour << "h " << min << "m " << sec << "s " << fmod(difference, 1000) << "ms ";
}