Skip to content

Instantly share code, notes, and snippets.

@bjorn
Created August 17, 2012 17:47
Show Gist options
  • Save bjorn/3380952 to your computer and use it in GitHub Desktop.
Save bjorn/3380952 to your computer and use it in GitHub Desktop.
Duration Logger (Qt)
#ifndef DURATIONLOGGER_H
#define DURATIONLOGGER_H
#include <QTime>
/**
* A helper class that logs the duration of a specific scope.
*/
class DurationLogger
{
public:
DurationLogger(const char *thing) : thing(thing) { time.start(); }
~DurationLogger() { qDebug() << thing << time.elapsed(); }
private:
QTime time;
const char *thing;
};
/**
* Use this macro in functions to conveniently time their duration.
*/
#define LOG_DURATION DurationLogger _durationLogger(Q_FUNC_INFO)
#endif // DURATIONLOGGER_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment