diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:10:11 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:10:11 +0200 |
commit | c0cdb2ad99a1e2a6ade5ce76c91177a79258e669 (patch) | |
tree | 4701a015385d9a6a5a4ba99a8f1f5d400fff26b1 /shared/perf.h | |
parent | 3.13 (diff) | |
download | FreeFileSync-c0cdb2ad99a1e2a6ade5ce76c91177a79258e669.tar.gz FreeFileSync-c0cdb2ad99a1e2a6ade5ce76c91177a79258e669.tar.bz2 FreeFileSync-c0cdb2ad99a1e2a6ade5ce76c91177a79258e669.zip |
3.14
Diffstat (limited to 'shared/perf.h')
-rw-r--r-- | shared/perf.h | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/shared/perf.h b/shared/perf.h index 4f955748..1ad4650d 100644 --- a/shared/perf.h +++ b/shared/perf.h @@ -7,22 +7,34 @@ #ifndef DEBUG_PERF_HEADER #define DEBUG_PERF_HEADER +#include <sstream> //#define WIN32_LEAN_AND_MEAN -> not in a header +/* +#include <windows.h> +#undef max +#undef min +*/ #include <wx/msw/wrapwin.h> //includes "windows.h" -#include <sstream> + #ifdef __MINGW32__ - #define DEPRECATED(x) x __attribute__ ((deprecated)) +#define DEPRECATED(x) x __attribute__ ((deprecated)) #elif defined _MSC_VER - #define DEPRECATED(x) __declspec(deprecated) x +#define DEPRECATED(x) __declspec(deprecated) x #endif -class Performance +class CpuTimer { public: - DEPRECATED(Performance()) : resultWasShown(false), startTime(::GetTickCount()) {} + class TimerError {}; - ~Performance() + DEPRECATED(CpuTimer()) : resultWasShown(false), startTime(), frequency() + { + if (!::QueryPerformanceFrequency(&frequency)) throw TimerError(); + if (!::QueryPerformanceCounter (&startTime)) throw TimerError(); + } + + ~CpuTimer() { if (!resultWasShown) showResult(); @@ -30,23 +42,27 @@ public: void showResult() { - const DWORD delta = ::GetTickCount() - startTime; + LARGE_INTEGER currentTime = {}; + if (!::QueryPerformanceCounter(¤tTime)) throw TimerError(); + + const long delta = 1000.0 * (currentTime.QuadPart - startTime.QuadPart) / frequency.QuadPart; std::ostringstream ss; ss << delta << " ms"; - + ::MessageBoxA(NULL, ss.str().c_str(), "Timer", 0); resultWasShown = true; - startTime = ::GetTickCount(); //don't include call to MessageBox()! + if (!::QueryPerformanceCounter(&startTime)) throw TimerError(); //don't include call to MessageBox()! } - + private: bool resultWasShown; - DWORD startTime; + LARGE_INTEGER startTime; + LARGE_INTEGER frequency; }; //two macros for quick performance measurements -#define PERF_START Performance a; -#define PERF_STOP a.showResult(); +#define PERF_START CpuTimer perfTest; +#define PERF_STOP perfTest.showResult(); -#endif //DEBUG_PERF_HEADER
\ No newline at end of file +#endif //DEBUG_PERF_HEADER |