00001 #ifndef moses_Time_H
00002 #define moses_Time_H
00003
00004 #include <ctime>
00005 #include <iostream>
00006 #include <iomanip>
00007 #include "Util.h"
00008
00009 namespace Moses
00010 {
00011
00017 class Timer
00018 {
00019 friend std::ostream& operator<<(std::ostream& os, Timer& t);
00020
00021 private:
00022 bool running;
00023
00024
00025 #ifdef CLOCK_MONOTONIC
00026 struct timespec start_time;
00027 #else
00028 time_t start_time;
00029 #endif
00030
00031
00032 double elapsed_time();
00033
00034 public:
00035
00036
00037
00038
00039 Timer() : running(false) {
00040 #ifdef CLOCK_MONOTONIC
00041 start_time.tv_sec = 0;
00042 start_time.tv_nsec = 0;
00043 #else
00044 start_time = 0;
00045 #endif
00046 }
00047
00048 void start(const char* msg = 0);
00049
00050
00051 void check(const char* msg = 0);
00052 double get_elapsed_time();
00053
00054 };
00055
00056 }
00057
00058 #endif