From ee48eb96e8228d922a8db2259a4f3666e45b0bd7 Mon Sep 17 00:00:00 2001
From: bothameister <bothameister@ec762483-ff6d-05da-a07a-a48fb63a330f>
Date: Fri, 2 Jul 2010 02:47:27 +0000
Subject: changed timer mechanism to play nice with multiple threads

git-svn-id: https://ws10smt.googlecode.com/svn/trunk@99 ec762483-ff6d-05da-a07a-a48fb63a330f
---
 gi/pyp-topics/src/pyp-topics.cc | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

(limited to 'gi/pyp-topics')

diff --git a/gi/pyp-topics/src/pyp-topics.cc b/gi/pyp-topics/src/pyp-topics.cc
index 0f13cd35..d8a8d815 100644
--- a/gi/pyp-topics/src/pyp-topics.cc
+++ b/gi/pyp-topics/src/pyp-topics.cc
@@ -1,21 +1,28 @@
 #include "pyp-topics.hh"
 //#include "mt19937ar.h"
 
-#include <ctime>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+#include <sys/time.h>
 
 struct Timer {
   Timer() { Reset(); }
-  void Reset() { start_t = clock(); }
+  void Reset() 
+  { 
+   clock_gettime(CLOCK_MONOTONIC, &start_t); 
+  }
   double Elapsed() const {
-    const clock_t end_t = clock();
-    const double elapsed = (end_t - start_t) / 1000000.0;
+    timespec end_t;
+  
+    clock_gettime(CLOCK_MONOTONIC, &end_t); 
+  
+    const double elapsed = (end_t.tv_sec - start_t.tv_sec) 
+                + (end_t.tv_nsec - start_t.tv_nsec) / 1000000000.0;
     return elapsed;
   }
  private:
-  std::clock_t start_t;
+  timespec start_t;
 };
 
-
 void PYPTopics::sample(const Corpus& corpus, int samples) {
   Timer timer;
 
-- 
cgit v1.2.3