stop_watch.h
Go to the documentation of this file.
00001 
00060 #ifndef STOPWATCH_H_
00061 #define STOPWATCH_H_
00062 
00063 
00064 #include <ctime>
00065 #include <sstream>
00066 #include <sys/time.h>
00067 #ifdef _WIN32
00068 #include <Windows.h>
00069 #endif
00070 
00071 
00075 class SimpleStopWatch {
00076         clock_t startClock;
00077 
00078 public:
00080         void start() { startClock = clock(); };
00081 
00083         double stop() { return ((double)(clock()-startClock))/(double)CLOCKS_PER_SEC; };
00084 };
00085 
00086 
00090 #ifdef _WIN32
00091 class PrecisionStopWatch {
00092         LARGE_INTEGER precisionClock;
00093         LARGE_INTEGER precisionFrequency;
00094 
00095 public:
00096         PrecisionStopWatch() {
00097                 precisionClock.QuadPart = 0;
00098                 if(!QueryPerformanceFrequency(&precisionFrequency)) printf("PrecisionStopWatch: Error: Frequency query failed.\n");
00099         };
00100 
00102         void precisionStart() {
00103                 if(!QueryPerformanceCounter(&precisionClock)) printf("PrecisionStopWatch: Error: precisionStart query failed.\n");
00104         };
00105 
00107         double precisionStop() {
00108                 LARGE_INTEGER precisionClockEnd;
00109                 if(!QueryPerformanceCounter(&precisionClockEnd)) printf("PrecisionStopWatch: Error: precisionStop query failed.\n");
00110                 return (double)(precisionClockEnd.QuadPart - precisionClock.QuadPart) / (double)precisionFrequency.QuadPart;
00111         };
00112 };
00113 #else
00114 /*
00115  * Linux version of precision host timer. See http://www.informit.com/articles/article.aspx?p=23618&seqNum=8
00116  */
00117 class PrecisionStopWatch {
00118         struct timeval precisionClock;
00119 
00120 public:
00121         PrecisionStopWatch() {
00122                 gettimeofday(&precisionClock, NULL);
00123         };
00124 
00125         void precisionStart() {
00126                 gettimeofday(&precisionClock, NULL);
00127         };
00128 
00129         double precisionStop() {
00130                 struct timeval precisionClockEnd;
00131                 gettimeofday(&precisionClockEnd, NULL);
00132                 return ((double)precisionClockEnd.tv_sec + 1.0e-6 * (double)precisionClockEnd.tv_usec) - ((double)precisionClock.tv_sec + 1.0e-6 * (double)precisionClock.tv_usec);
00133         };
00134 };
00135 #endif
00136 
00137 #endif //STOPWATCH_H_


cob_3d_mapping_common
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:02:19