00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _TT_H
00021 #define _TT_H
00022
00023 #include <sys/time.h>
00024 #include <unistd.h>
00025
00026 #define microsec 1000000.0
00027
00032 class time_tracker {
00033 private:
00034 struct timeval start_time;
00035 struct timeval stop_time;
00036 bool running;
00037 double curr_time;
00038 public:
00039 time_tracker() {
00040 running=false;
00041 curr_time=0;
00042 }
00043
00045 void start() {
00046 gettimeofday(&start_time, (struct timezone *)0);
00047 running=true;
00048 }
00049
00051 void stop() {
00052 double st, en;
00053 if (!running) return;
00054 else {
00055 gettimeofday(&stop_time, (struct timezone *)0);
00056 st = start_time.tv_sec + (start_time.tv_usec/microsec);
00057 en = stop_time.tv_sec + (stop_time.tv_usec/microsec);
00058 running=false;
00059 curr_time+=en-st;
00060 }
00061 }
00062
00063 double print() const
00064 { return curr_time; }
00065 };
00066
00067 #endif