00001 #ifdef WIN32 00002 00003 #include <iostream> 00004 #include "Timer.h" 00005 00006 using namespace std; 00007 00008 Timer::Timer(char *name, int id) 00009 { 00010 LARGE_INTEGER freq; 00011 this->name = name; 00012 00013 QueryPerformanceFrequency(&freq); 00014 resolution = (double) freq.HighPart * 4294967296.0; 00015 resolution += (double) freq.LowPart; 00016 resolution = 1.0 / resolution; 00017 00018 this->id = id; 00019 _verbose = true; 00020 } 00021 00022 00023 Timer::~Timer() 00024 { 00025 } 00026 00027 00028 void 00029 Timer::start(void) 00030 { 00031 QueryPerformanceCounter(&startTime); 00032 lastTime = startTime; 00033 lapCount = 1; 00034 } 00035 00036 00037 double 00038 Timer::lap(char *event) 00039 { 00040 LARGE_INTEGER now; 00041 double elapsedTime; 00042 00043 QueryPerformanceCounter(&now); 00044 elapsedTime = ((double)now.HighPart - (double)lastTime.HighPart) 00045 * 4294967296.0; 00046 elapsedTime += (double)now.LowPart - (double)lastTime.LowPart; 00047 elapsedTime *= resolution; 00048 00049 lastTime = now; 00050 lapCount++; 00051 if(_verbose) 00052 { 00053 cout << name << "[" << id << ":" << lapCount << "-" 00054 << event << "]: " << elapsedTime << endl; 00055 } 00056 00057 return elapsedTime; 00058 } 00059 00060 00061 double 00062 Timer::et(void) 00063 { 00064 LARGE_INTEGER now; 00065 double elapsedTime; 00066 00067 QueryPerformanceCounter(&now); 00068 elapsedTime = ((double)now.HighPart - (double)startTime.HighPart) 00069 * 4294967296.0; 00070 elapsedTime += (double)now.LowPart - (double)startTime.LowPart; 00071 elapsedTime *= resolution; 00072 00073 if(_verbose) 00074 { 00075 cout << name << "[ET " << id << "]: " << elapsedTime << endl; 00076 } 00077 00078 return elapsedTime; 00079 } 00080 00081 #endif //if def windows 00082