Possible Duplicate:
measuring time with resolution of microseconds in c++?
Hi,
Is there a simple way i can get the system time on a Windows machine, down to microsecond accuracy?
Look at GetSystemTimeAsFileTime
It gives you accuracy in 0.1 microseconds or 100 nanoseconds.
Note that it's Epoch different from POSIX Epoch.
So to get POSIX time in microseconds you need:
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
unsigned long long tt = ft.dwHighDateTime;
tt <<=32;
tt |= ft.dwLowDateTime;
tt /=10;
tt -= 11644473600000000ULL;
So in such case time(0) == tt / 1000000
Like this
unsigned __int64 freq;
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
double timerFrequency = (1.0/freq);
unsigned __int64 startTime;
QueryPerformanceCounter((LARGE_INTEGER *)&startTime);
//do something...
unsigned __int64 endTime;
QueryPerformanceCounter((LARGE_INTEGER *)&endTime);
double timeDifferenceInMilliseconds = ((endTime-startTime) * timerFrequency);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With