From c97ede5c3466a34f3537a198a88c65525e3f0749 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Fri, 13 Jan 2012 11:11:34 -0600 Subject: [PATCH] fix windows version of GetRunningMicroSecs() --- common/getrunningmicrosecs.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/common/getrunningmicrosecs.cpp b/common/getrunningmicrosecs.cpp index 895b2bc26d..12082fae3e 100644 --- a/common/getrunningmicrosecs.cpp +++ b/common/getrunningmicrosecs.cpp @@ -40,23 +40,34 @@ unsigned GetRunningMicroSecs() unsigned GetRunningMicroSecs() { - LARGE_INTEGER curtime; + FILETIME now; - static unsigned timerFreq; // timer frequency + GetSystemTimeAsFileTime( &now ); - if( !timerFreq ) - { - QueryPerformanceFrequency( &curtime ); + typedef unsigned long long UINT64; - timerFreq = curtime.QuadPart / 1000000; // i.e., ticks per usec + UINT64 t = (UINT64(now.dwHighDateTime) << 32) + now.dwLowDateTime; - assert( timerFreq ); - } + t /= 10; - QueryPerformanceCounter( &curtime ); - - return ( curtime.LowPart / timerFreq ); + return unsigned( t ); } + +#if 0 +// test program +#include +int main( int argc, char** argv ) +{ + unsigned then = GetRunningMicroSecs(); + + Sleep( 2000 ); // Windows Sleep( msecs ) + + printf( "delta: %u\n", GetRunningMicroSecs() - then ); + + return 0; +} +#endif + #endif