diff options
author | bothameister <bothameister@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-02 02:47:27 +0000 |
---|---|---|
committer | bothameister <bothameister@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-02 02:47:27 +0000 |
commit | ee48eb96e8228d922a8db2259a4f3666e45b0bd7 (patch) | |
tree | 32540153f4210c93c9fe162f2c5c65048184aa34 /gi/pyp-topics | |
parent | 72c705df4fefe32792ed7c75f39b06da5061870e (diff) |
changed timer mechanism to play nice with multiple threads
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@99 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'gi/pyp-topics')
-rw-r--r-- | gi/pyp-topics/src/pyp-topics.cc | 19 |
1 files changed, 13 insertions, 6 deletions
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; |