00001 00002 #include <iostream> 00003 #define NOMINMAX 00004 #include <windows.h> 00005 00006 struct profiler_timemeasurement_t 00007 { 00008 __int64 start; 00009 __int64 end; 00010 __int64* freq; 00011 00012 public: 00013 double getMeasuredTime() 00014 { 00015 return (double)(((long double)(end-start))/((long double)*freq)); 00016 } 00017 void printToConsole(const char* caption) 00018 { 00019 cout << caption << ":\t" << getMeasuredTime() << "\n"; 00020 } 00021 }; 00022 class GProfiler 00023 { 00024 public: 00025 static profiler_timemeasurement_t Start() 00026 { 00027 profiler_timemeasurement_t link; 00028 00029 QueryPerformanceCounter( (LARGE_INTEGER*) &(link.start) ); 00030 link.freq = getFrequency(); 00031 00032 return link; 00033 } 00034 static void Stop(profiler_timemeasurement_t& link) 00035 { 00036 QueryPerformanceCounter( (LARGE_INTEGER*) &(link.end) ); 00037 } 00038 00039 private: 00040 static __int64* getFrequency() 00041 { 00042 static __int64 freq = 0; 00043 00044 if (freq == 0) 00045 QueryPerformanceFrequency( (LARGE_INTEGER*) &freq); 00046 00047 return &freq; 00048 } 00049 };