HG-MD  1
Time.h
Go to the documentation of this file.
00001 #ifndef TIME_H
00002 #define TIME_H
00003 
00004 #include <ctime>
00005 #include <time.h>
00006 #include <string.h>
00007 #include <sstream>
00008 using namespace std;
00009 
00013 class Time {
00014         
00015 public:
00016         void tic() {start = clock();}
00017         Mdouble toc() {finish = clock();        return (Mdouble(finish)-Mdouble(start))/CLOCKS_PER_SEC;         }
00018         
00019 private:
00020         clock_t start,finish;
00021         
00022 };
00023 
00025 class Time2Finish {
00026         
00027 public:
00028         void set(Mdouble t, Mdouble tmax) {start = clock(); t_=t; tmax_=tmax;}
00029         
00030         Mdouble getTime2Finish(Mdouble t) {
00031                 clock_t finish = clock();
00032                 Mdouble elapsedTime = (Mdouble(finish)-Mdouble(start))/CLOCKS_PER_SEC;
00033                 Mdouble time2Finish = elapsedTime*(tmax_-t_)/(t-t_);
00034                 start = finish;
00035                 t_ = t;
00036                 return time2Finish;     
00037         }
00038         
00039         string getFinishTime(Mdouble t) {       
00040                 Mdouble time2Finish = getTime2Finish(t);
00041                 time_t finish = time(NULL) + time2Finish;
00042                 stringstream ss;
00043                 //write estimated end time
00044                 ss << ctime(&finish);
00045                 //decrement put pointer by one to avoid line break
00046                 ss.seekp((long)ss.tellp()-1);
00047                 //write time to finish
00048                 ss << " (" << time2Finish/3600 << "h)";
00049                 return ss.str();
00050         }
00051         
00052 private:
00053         clock_t start;
00054         Mdouble t_, tmax_;
00055         
00056 };
00057 
00058 
00059 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines