Skip to content

Instantly share code, notes, and snippets.

@nkuln
Created October 19, 2011 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkuln/1297979 to your computer and use it in GitHub Desktop.
Save nkuln/1297979 to your computer and use it in GitHub Desktop.
Demonstrate problem from getting 64-bit timestamp to nanosec in Windows
// Demonstrate problem in GetSystemTimeAsFileTime(..) call
// The time returned is not very precised
//
ULARGE_INTEGER prev_timestamp, timestamp;
prev_timestamp.QuadPart = 0;
for(int i = 0 ; i < 100 ; ++i, prev_timestamp = timestamp){
FILETIME now;
GetSystemTimeAsFileTime(&now);
timestamp.HighPart = now.dwHighDateTime;
timestamp.LowPart = now.dwLowDateTime;
ULONGLONG diff = timestamp.QuadPart - prev_timestamp.QuadPart;
// The unit for timestamp's diff is 10 nanosecond or 0.1 microsecond
// Divide this number by 10 to convert unit to microsecond
//
if(diff != 0)
printf("TIMESTAMP DIFF = %I64u\n\n", diff);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment