Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2012-11-12 23:56:18 +0400
committerHieu Hoang <hieuhoang@gmail.com>2012-11-12 23:56:18 +0400
commit5e3ef23cef6101d2c098eb3445f562e8f595655b (patch)
treeb8c332b6fa82bae84ea4910967a10ba1b08a7107 /moses/Timer.h
parent8c785cff2b1be3cccd76ea9026f71b649762dfc3 (diff)
move moses/src/* to moses/
Diffstat (limited to 'moses/Timer.h')
-rw-r--r--moses/Timer.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/moses/Timer.h b/moses/Timer.h
new file mode 100644
index 000000000..be2fbc6ab
--- /dev/null
+++ b/moses/Timer.h
@@ -0,0 +1,58 @@
+#ifndef moses_Time_H
+#define moses_Time_H
+
+#include <ctime>
+#include <iostream>
+#include <iomanip>
+#include "Util.h"
+
+namespace Moses
+{
+
+/** Wrapper around time_t to time how long things have been running
+ * 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.
+ */
+class Timer
+{
+ friend std::ostream& operator<<(std::ostream& os, Timer& t);
+
+private:
+ bool running;
+ // 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
+#ifdef CLOCK_MONOTONIC
+ struct timespec start_time;
+#else
+ time_t start_time;
+#endif
+
+ // in seconds
+ double elapsed_time();
+
+public:
+ /***
+ * 'running' is initially false. A timer needs to be explicitly started
+ * using 'start' or 'restart'
+ */
+ Timer() : running(false) {
+#ifdef CLOCK_MONOTONIC
+ start_time.tv_sec = 0;
+ start_time.tv_nsec = 0;
+#else
+ start_time = 0;
+#endif
+ }
+
+ 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();
+
+};
+
+}
+
+#endif