00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00026 #ifndef __SAVA_TIME_STOPWATCH_H
00027 #define __SAVA_TIME_STOPWATCH_H
00028
00029 #include <sys/time.h>
00030 #include <sys/types.h>
00031 #include <unistd.h>
00032
00033 #include <libsava/packages.h>
00034
00035 __BEGIN_PACKAGE_SAVA_TIME
00036
00044 class StopWatch {
00045 double startTime, endTime;
00046
00047 public:
00048
00052 StopWatch() : startTime(0.0), endTime(0.0) { }
00053
00057 void start() {
00058 struct timeval t;
00059 struct timezone tz;
00060
00061 gettimeofday(&t, &tz);
00062 startTime =
00063 static_cast<double>(t.tv_sec) + static_cast<double>(t.tv_usec)/1e6;
00064 }
00065
00069 void stop() {
00070 struct timeval t;
00071 struct timezone tz;
00072
00073 gettimeofday(&t, &tz);
00074 endTime =
00075 static_cast<double>(t.tv_sec) + static_cast<double>(t.tv_usec)/1e6;
00076 }
00077
00083 double elapsed() {
00084 return (endTime - startTime);
00085 }
00086 };
00087
00088 __END_PACKAGE_SAVA_TIME
00089
00090 #endif
Copyright © 2003-2005 Savarese Software Research and Daniel F. Savarese. All rights reserved.