mirror-chatterino2/src/debug/Benchmark.hpp

42 lines
834 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__ \
2018-05-25 12:45:18 +02:00
<< static_cast<float>(x.nsecsElapsed()) / 1000000.0 << "ms";
2018-06-26 16:37:59 +02:00
namespace chatterino {
2018-05-25 12:45:18 +02:00
class BenchmarkGuard : boost::noncopyable
{
QElapsedTimer timer;
QString name;
public:
BenchmarkGuard(const QString &_name)
2018-05-25 12:45:18 +02:00
: name(_name)
{
timer.start();
}
2018-05-25 12:45:18 +02:00
~BenchmarkGuard()
{
qDebug() << this->name << float(timer.nsecsElapsed()) / 1000000.0f << "ms";
}
2018-05-25 12:45:18 +02:00
qreal getElapsedMs()
{
return qreal(timer.nsecsElapsed()) / 1000000.0;
}
};
2018-06-26 16:37:59 +02:00
} // namespace chatterino