2010-02-24 14:15:44 +03:00
|
|
|
#ifndef moses_Time_H
|
|
|
|
#define moses_Time_H
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include "Util.h"
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
2012-06-29 02:29:46 +04:00
|
|
|
/** Wrapper around time_t to time how long things have been running
|
2012-08-10 23:24:01 +04:00
|
|
|
* according to walltime. We avoid CPU time since it is less reliable
|
|
|
|
* in a multi-threaded environment and can spuriously include clock cycles
|
|
|
|
* used by other threads in the same process.
|
2012-06-29 02:29:46 +04:00
|
|
|
*/
|
2008-06-11 14:52:57 +04:00
|
|
|
class Timer
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream& os, Timer& t);
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
private:
|
2008-06-11 14:52:57 +04:00
|
|
|
bool running;
|
2012-08-10 23:24:01 +04:00
|
|
|
// note: this only has the resolution of seconds, we'd often like better resolution
|
|
|
|
// we make our best effort to do this on a system-by-system basis
|
2008-06-11 14:52:57 +04:00
|
|
|
time_t start_time;
|
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
// in seconds
|
2008-06-11 14:52:57 +04:00
|
|
|
double elapsed_time();
|
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
public:
|
2008-06-11 14:52:57 +04:00
|
|
|
/***
|
|
|
|
* 'running' is initially false. A timer needs to be explicitly started
|
|
|
|
* using 'start' or 'restart'
|
|
|
|
*/
|
2012-08-10 23:24:01 +04:00
|
|
|
Timer() : running(false) {
|
2013-05-29 21:16:15 +04:00
|
|
|
start_time = 0;
|
2012-08-10 23:24:01 +04:00
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
void start(const char* msg = 0);
|
|
|
|
// void restart(const char* msg = 0);
|
|
|
|
// void stop(const char* msg = 0);
|
|
|
|
void check(const char* msg = 0);
|
|
|
|
double get_elapsed_time();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|