/* Return <ft1> - <ft2> in seconds */ int FileTimeDiffInSecs(FILETIME& ft1, FILETIME& ft2) { ULARGE_INTEGER t1 = FileTimeToLargeInteger(ft1); ULARGE_INTEGER t2 = FileTimeToLargeInteger(ft2); // diff is in 100 nanoseconds LONGLONG diff = t1.QuadPart - t2.QuadPart; diff = diff / (LONGLONG)10000000L; return (int)diff; }
LPTSTR FileTimeToText( LPTSTR szBuffer, LPTSTR szEndChar, PFILETIME pFt, BOOL bTextForEdit) { int nLength; if(bTextForEdit == FALSE) { // First part: date as LARGE_INTEGER szBuffer = FileTimeToLargeInteger(szBuffer, szEndChar, pFt); // Add one space if(szEndChar > szBuffer) *szBuffer++ = _T(' '); // Append the filetime in human-readable form nLength = FileTimeToHumanReadableText(szBuffer, szEndChar, pFt, TRUE); szBuffer += nLength; } else { // Attempt to convert the filetime to human-readable form nLength = FileTimeToHumanReadableText(szBuffer, szEndChar, pFt, FALSE); // If failed, just convert it to LARGE_INTEGER if(nLength == 0) { szBuffer = FileTimeToLargeInteger(szBuffer, szEndChar, pFt); } else { szBuffer += nLength; } } return szBuffer; }
// This is meant to measure program startup time from the user perspective. // One place to measure it is at the beginning of WinMain(). // Another place is on the first run of WM_PAINT of the message loop of main window. double GetProcessRunningTime() { FILETIME currTime, startTime, d1, d2, d3; GetSystemTimeAsFileTime(&currTime); HANDLE hproc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId()); double timeInMs = 0; if (!hproc) return 0; if (GetProcessTimes(hproc, &startTime, &d1, &d2, &d3)) { ULARGE_INTEGER start = FileTimeToLargeInteger(startTime); ULARGE_INTEGER curr = FileTimeToLargeInteger(currTime); ULONGLONG diff = curr.QuadPart - start.QuadPart; // FILETIME is in 100 ns chunks timeInMs = ((double)(diff * 100)) / (double)1000000; } CloseHandle(hproc); return timeInMs; }