functiontimer: created convenience class to help when profiling functions

This commit is contained in:
itsmattkc
2020-02-20 17:47:33 +11:00
parent e373c40853
commit 8cb74a8218
2 changed files with 34 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
#ifndef FUNCTIONTIMER_H
#define FUNCTIONTIMER_H
#include <QDateTime>
#include <QDebug>
#define TIME_THIS_FUNCTION FunctionTimer __f(__FUNCTION__)
class FunctionTimer {
public:
FunctionTimer(const char* s)
{
name_ = s;
time_ = QDateTime::currentMSecsSinceEpoch();
}
~FunctionTimer()
{
qint64 elapsed = (QDateTime::currentMSecsSinceEpoch() - time_);
if (elapsed > 1) {
qDebug() << name_ << "took" << elapsed;
}
}
private:
const char* name_;
qint64 time_;
};
#endif // FUNCTIONTIMER_H