mirror-chatterino2/src/util/benchmark.hpp

35 lines
769 B
C++
Raw Normal View History

2017-10-08 17:23:46 +02:00
#pragma once
#include <QDebug>
#include <QElapsedTimer>
#include <boost/current_function.hpp>
#include <boost/noncopyable.hpp>
2017-10-08 17:23:46 +02:00
#define BENCH(x) \
QElapsedTimer x; \
x.start();
#define MARK(x) \
qDebug() << BOOST_CURRENT_FUNCTION << __LINE__ \
<< static_cast<float>(x.nsecsElapsed()) / 100000.0 << "ms";
class BenchmarkGuard : boost::noncopyable {
QElapsedTimer timer;
QString name;
public:
BenchmarkGuard(const QString &_name)
:name(_name)
{
timer.start();
}
~BenchmarkGuard() {
qDebug() << this->name << float(timer.nsecsElapsed()) / 100000.0 << "ms";
}
qreal getElapsedMs() {
return qreal(timer.nsecsElapsed()) / 100000.0;
}
};