summaryrefslogtreecommitdiff
path: root/shared/perf.h
diff options
context:
space:
mode:
Diffstat (limited to 'shared/perf.h')
-rw-r--r--shared/perf.h31
1 files changed, 22 insertions, 9 deletions
diff --git a/shared/perf.h b/shared/perf.h
index 1ad4650d..641eee2b 100644
--- a/shared/perf.h
+++ b/shared/perf.h
@@ -8,13 +8,15 @@
#define DEBUG_PERF_HEADER
#include <sstream>
+
+#ifdef __WXWINDOWS__
+#include <wx/msw/wrapwin.h> //includes "windows.h"
+#else
//#define WIN32_LEAN_AND_MEAN -> not in a header
-/*
#include <windows.h>
#undef max
#undef min
-*/
-#include <wx/msw/wrapwin.h> //includes "windows.h"
+#endif
#ifdef __MINGW32__
@@ -28,37 +30,48 @@ class CpuTimer
public:
class TimerError {};
- DEPRECATED(CpuTimer()) : resultWasShown(false), startTime(), frequency()
+ DEPRECATED(CpuTimer()) : frequency(), startTime(), resultShown(false)
{
+ SetThreadAffinity dummy;
if (!::QueryPerformanceFrequency(&frequency)) throw TimerError();
if (!::QueryPerformanceCounter (&startTime)) throw TimerError();
}
~CpuTimer()
{
- if (!resultWasShown)
+ if (!resultShown)
showResult();
}
void showResult()
{
+ SetThreadAffinity dummy;
LARGE_INTEGER currentTime = {};
if (!::QueryPerformanceCounter(&currentTime)) throw TimerError();
- const long delta = 1000.0 * (currentTime.QuadPart - startTime.QuadPart) / frequency.QuadPart;
+ const long delta = static_cast<long>(1000.0 * (currentTime.QuadPart - startTime.QuadPart) / frequency.QuadPart);
std::ostringstream ss;
ss << delta << " ms";
::MessageBoxA(NULL, ss.str().c_str(), "Timer", 0);
- resultWasShown = true;
+ resultShown = true;
if (!::QueryPerformanceCounter(&startTime)) throw TimerError(); //don't include call to MessageBox()!
}
private:
- bool resultWasShown;
- LARGE_INTEGER startTime;
+ class SetThreadAffinity
+ {
+ public:
+ SetThreadAffinity() : oldmask(::SetThreadAffinityMask(::GetCurrentThread(), 1)) { if (oldmask == 0) throw TimerError(); }
+ ~SetThreadAffinity() { ::SetThreadAffinityMask(::GetCurrentThread(), oldmask); }
+ private:
+ const DWORD_PTR oldmask;
+ };
+
LARGE_INTEGER frequency;
+ LARGE_INTEGER startTime;
+ bool resultShown;
};
//two macros for quick performance measurements
bgstack15