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;
|
2014-01-03 22:45:31 +04:00
|
|
|
bool stopped;
|
2014-01-02 01:19:06 +04:00
|
|
|
double start_time;
|
2014-01-03 22:45:31 +04:00
|
|
|
double stop_time;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
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
|
2014-01-02 01:19:06 +04:00
|
|
|
* using 'start'
|
2008-06-11 14:52:57 +04:00
|
|
|
*/
|
2014-01-03 22:45:31 +04:00
|
|
|
Timer() : running(false),stopped(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);
|
2014-01-03 22:45:31 +04:00
|
|
|
void stop(const char* msg = 0);
|
2008-06-11 14:52:57 +04:00
|
|
|
void check(const char* msg = 0);
|
2014-01-03 22:45:31 +04:00
|
|
|
double get_elapsed_time() const;
|
2008-06-11 14:52:57 +04:00
|
|
|
};
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|