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?
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
GetSystemTime()
... but the issue is, it's absolute time, not relative time. It isn't good for use inside a program to figure out time elapsed, as absolute time can change for various random reasons (e.g. time sync). –
Lombard KeQuerySystemTime
: "System time is typically updated approximately every ten milliseconds." –
Hysteric GetSystemTimePreciseAsFileTime()
–
Possessed 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);
What we really need is a high-resolution GetTickCount()
. As far as I know, this doesn't really exist.
If you're willing to use a hackish way to solve this (that would probably only work on some versions of Windows like XP), look here at ReactOS. Then try this code:
long long GetTickCount64()
{
return (long long)
((((unsigned long long)*(unsigned long int*)0x7FFE0000
* (unsigned long long)*(unsigned long int*)0x7FFE0004)
* (unsigned long long)10000) >> 0x18);
}
Tweaking it might give you what you need in some versions of Windows.
NtQueryTimerResolution
which returns this exact value (the time increment). –
Hysteric KeQueryTickCount
, but I don't know what the relationship is between KeQueryTickCount
and the USER_SHARED_DATA structure which your NtGetTickCount64
function uses. CBB doing more disassembling. –
Hysteric NtQuerySystemInformation
with SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
and adding up the values... –
Lombard © 2022 - 2024 — McMap. All rights reserved.