2017-10-08 17:23:46 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QElapsedTimer>
|
2017-10-11 10:34:04 +02:00
|
|
|
#include <boost/current_function.hpp>
|
2018-05-24 22:58:07 +02:00
|
|
|
#include <boost/noncopyable.hpp>
|
2017-10-08 17:23:46 +02:00
|
|
|
|
|
|
|
#define BENCH(x) \
|
|
|
|
QElapsedTimer x; \
|
|
|
|
x.start();
|
|
|
|
|
2017-10-11 10:34:04 +02:00
|
|
|
#define MARK(x) \
|
|
|
|
qDebug() << BOOST_CURRENT_FUNCTION << __LINE__ \
|
2018-05-25 12:45:18 +02:00
|
|
|
<< static_cast<float>(x.nsecsElapsed()) / 1000000.0 << "ms";
|
2018-05-24 22:58:07 +02:00
|
|
|
|
2018-05-25 12:45:18 +02:00
|
|
|
class BenchmarkGuard : boost::noncopyable
|
|
|
|
{
|
2018-05-24 22:58:07 +02:00
|
|
|
QElapsedTimer timer;
|
|
|
|
QString name;
|
|
|
|
|
|
|
|
public:
|
|
|
|
BenchmarkGuard(const QString &_name)
|
2018-05-25 12:45:18 +02:00
|
|
|
: name(_name)
|
2018-05-24 22:58:07 +02:00
|
|
|
{
|
|
|
|
timer.start();
|
|
|
|
}
|
|
|
|
|
2018-05-25 12:45:18 +02:00
|
|
|
~BenchmarkGuard()
|
|
|
|
{
|
|
|
|
qDebug() << this->name << float(timer.nsecsElapsed()) / 1000000.0f << "ms";
|
2018-05-24 22:58:07 +02:00
|
|
|
}
|
|
|
|
|
2018-05-25 12:45:18 +02:00
|
|
|
qreal getElapsedMs()
|
|
|
|
{
|
|
|
|
return qreal(timer.nsecsElapsed()) / 1000000.0;
|
2018-05-24 22:58:07 +02:00
|
|
|
}
|
|
|
|
};
|