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:
authorphikoehn <pkoehn@inf.ed.ac.uk>2014-01-03 22:45:31 +0400
committerphikoehn <pkoehn@inf.ed.ac.uk>2014-01-03 22:45:31 +0400
commit073a601eb0a7be3f3b1dc8000c8371dad18f5318 (patch)
treec8f890232dce04ece7952c939a392aec36c00106 /moses/Timer.cpp
parent14a499d9aa9c7f7be4fa2320a6b54fdcde3e2284 (diff)
make good use of the new precise timer...
Diffstat (limited to 'moses/Timer.cpp')
-rw-r--r--moses/Timer.cpp42
1 files changed, 36 insertions, 6 deletions
diff --git a/moses/Timer.cpp b/moses/Timer.cpp
index d1f6c4b8b..75f4154ec 100644
--- a/moses/Timer.cpp
+++ b/moses/Timer.cpp
@@ -12,9 +12,15 @@ namespace Moses
* Return the total wall time that the timer has been in the "running"
* state since it was first "started".
*/
-double Timer::get_elapsed_time()
+double Timer::get_elapsed_time() const
{
- return util::WallTime() - start_time;
+ if (stopped) {
+ return stop_time - start_time;
+ }
+ if (running) {
+ return util::WallTime() - start_time;
+ }
+ return 0;
}
/***
@@ -27,12 +33,36 @@ void Timer::start(const char* msg)
if (msg) TRACE_ERR( msg << std::endl);
// Return immediately if the timer is already running
- if (running) return;
+ if (running && !stopped) return;
- // Change timer status to running
- running = true;
+ // If stopped, recompute start time
+ if (stopped) {
+ start_time = util::WallTime() - (stop_time - start_time);
+ stopped = false;
+ }
+ else {
+ start_time = util::WallTime();
+ running = true;
+ }
+}
- start_time = util::WallTime();
+/***
+ * Stop a timer.
+ * Print an optional message.
+ */
+void Timer::stop(const char* msg)
+{
+ // Print an optional message, something like "Stopping timer t";
+ if (msg) TRACE_ERR( msg << std::endl);
+
+ // Return immediately if the timer is not running
+ if (stopped || !running) return;
+
+ // Record stopped time
+ stop_time = util::WallTime();
+
+ // Change timer status to running
+ stopped = true;
}
/***