summaryrefslogtreecommitdiff
path: root/src/common/include/gudhi/Clock.h
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2014-12-05 13:32:54 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2014-12-05 13:32:54 +0000
commit425b462d361286822ee0ed7b5fe00881ba312ea3 (patch)
treee8f641a8604418882b916573cf32c87b78d33472 /src/common/include/gudhi/Clock.h
parent952b77f3b1e2415602d5d9ffc2fb7ff45cc3edc4 (diff)
Moved into trunk
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@341 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Diffstat (limited to 'src/common/include/gudhi/Clock.h')
-rw-r--r--src/common/include/gudhi/Clock.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/common/include/gudhi/Clock.h b/src/common/include/gudhi/Clock.h
new file mode 100644
index 00000000..ea21659e
--- /dev/null
+++ b/src/common/include/gudhi/Clock.h
@@ -0,0 +1,67 @@
+/*
+ * Clock.h
+ *
+ * Created on: Jun 17, 2014
+ * Author: dsalinas
+ */
+
+#ifndef GUDHI_CLOCK_H_
+#define GUDHI_CLOCK_H_
+
+
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+class Clock{
+
+public:
+ Clock():end_called(false){
+ startTime = boost::posix_time::microsec_clock::local_time( );
+ }
+
+ Clock(const std::string& msg_){
+ end_called = false;
+ begin();
+ msg = msg_;
+ }
+
+
+ void begin() const{
+ end_called = false;
+ startTime = boost::posix_time::microsec_clock::local_time( );
+ }
+
+ void end() const{
+ end_called = true;
+ endTime = boost::posix_time::microsec_clock::local_time( );
+ }
+
+ void print() const{
+ std::cout << *this << std::endl;
+ }
+
+ friend std::ostream& operator<< (std::ostream& stream,const Clock& clock){
+ if(!clock.end_called)
+ clock.end();
+
+ if(!clock.end_called) stream << "end not called";
+ else{
+ stream << clock.msg <<":"<<clock.num_seconds() <<"s";
+ }
+ return stream;
+
+ }
+
+ double num_seconds() const{
+ if(!end_called) return -1;
+ return (endTime-startTime).total_milliseconds()/1000.;
+ }
+
+private:
+ mutable boost::posix_time::ptime startTime, endTime;
+ mutable bool end_called;
+ std::string msg;
+
+};
+
+
+#endif /* GUDHI_CLOCK_H_ */