mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
41 lines
834 B
C++
41 lines
834 B
C++
#pragma once
|
|
|
|
#include <QDebug>
|
|
#include <QElapsedTimer>
|
|
#include <boost/current_function.hpp>
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#define BENCH(x) \
|
|
QElapsedTimer x; \
|
|
x.start();
|
|
|
|
#define MARK(x) \
|
|
qDebug() << BOOST_CURRENT_FUNCTION << __LINE__ \
|
|
<< static_cast<float>(x.nsecsElapsed()) / 1000000.0 << "ms";
|
|
|
|
namespace chatterino {
|
|
|
|
class BenchmarkGuard : boost::noncopyable
|
|
{
|
|
QElapsedTimer timer;
|
|
QString name;
|
|
|
|
public:
|
|
BenchmarkGuard(const QString &_name)
|
|
: name(_name)
|
|
{
|
|
timer.start();
|
|
}
|
|
|
|
~BenchmarkGuard()
|
|
{
|
|
qDebug() << this->name << float(timer.nsecsElapsed()) / 1000000.0f << "ms";
|
|
}
|
|
|
|
qreal getElapsedMs()
|
|
{
|
|
return qreal(timer.nsecsElapsed()) / 1000000.0;
|
|
}
|
|
};
|
|
|
|
} // namespace chatterino
|