00001 #ifndef _CLOCKCLASS_H_
00002 #define _CLOCKCLASS_H_
00003
00004
00005
00006
00007 #include <unistd.h>
00008 #include <sys/time.h>
00009
00010 class RtsTimer_root
00011 {
00012 public:
00013
00014 timeval ts_old;
00015 timeval ts_last;
00016 timeval ts_new;
00017
00018 double t;
00019
00020 RtsTimer_root() {
00021 reset();
00022 }
00023
00024 void reset() {
00025 gettimeofday(&ts_old,NULL);
00026 ts_last = ts_old;
00027 }
00028
00029 double currtime() {
00030 gettimeofday(&ts_new, NULL);
00031 t = ts_new.tv_sec - ts_old.tv_sec;
00032 t += ((double)(ts_new.tv_usec - ts_old.tv_usec))/1000000.0;
00033
00034 return t;
00035 }
00036
00037 double record_time() {
00038 gettimeofday(&ts_new, NULL);
00039 t = ts_new.tv_sec - ts_last.tv_sec;
00040 t += ((double)(ts_new.tv_usec - ts_last.tv_usec))/1000000.0;
00041 ts_last = ts_new;
00042 return t;
00043 }
00044 };
00045
00046 #endif