Author Topic: System Precise Filetime, Unix Time and Elapsed Performance Counter Time  (Read 2629 times)

0 Members and 1 Guest are viewing this topic.

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
This is something I wrote today to compare the Windows System Precise Filetime with the Unix Time and the elapsed time computed by reading the Windows performance counter.

I welcome comments if there are alternative or better ways of getting time tags and elapsed times out of Windows.

Code: QB64: [Select]
  1. ' FILETIME structure
  2. ' This structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601.
  3. TYPE FILETIME
  4.     dwLowDateTime AS _UNSIGNED LONG
  5.     dwHighDateTime AS _UNSIGNED LONG
  6.  
  7.     ' GetSystemTimePreciseAsFileTime function
  8.     ' https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime
  9.     SUB GetSystemTimePreciseAsFileTime (BYVAL lpSystemTimeAsFileTime AS _UNSIGNED _OFFSET)
  10.  
  11.     ' Acquiring high-resolution time stamps
  12.     ' https://docs.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps
  13.     SUB QueryPerformanceCounter (BYVAL lpPerformanceCount AS _UNSIGNED _OFFSET)
  14.     SUB QueryPerformanceFrequency (BYVAL lpFrequency AS _UNSIGNED _OFFSET)
  15.  
  16.     ' time_t time( time_t *destTime )
  17.     ' Returns the time as seconds elapsed since midnight, January 1, 1970, or -1 in the case of an error.
  18.     ' https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/time-time32-time64?view=vs-2019
  19.     $IF 64BIT THEN
  20.     ' 64-bit OS, time_t type is 8 byte _INTEGER64
  21.     FUNCTION time&& (BYVAL TimerPtr AS _UNSIGNED _OFFSET)
  22.     $ELSE
  23.         ' 32-bit OS, time_t type is 4 byte INTEGER
  24.         FUNCTION time& (BYVAL TimerPtr AS _UNSIGNED _OFFSET)
  25.     $END IF
  26.  
  27. DIM ft AS FILETIME
  28. DIM time_now&
  29. DIM PerformanceCount AS _INTEGER64
  30. DIM Frequency AS _INTEGER64
  31. DIM StartingCount AS _INTEGER64
  32. DIM dElapsedTime AS DOUBLE
  33.  
  34. PRINT " System Precise FILETIME,    UNIX TIME,   Elapsed Performance Counter"
  35. QueryPerformanceFrequency (_OFFSET(Frequency))
  36. QueryPerformanceCounter (_OFFSET(StartingCount))
  37.  
  38. FOR i% = 1 TO 10
  39.     GetSystemTimePreciseAsFileTime (_OFFSET(ft))
  40.  
  41.     ' UNIX time
  42.     time_now& = time(0)
  43.  
  44.     QueryPerformanceCounter (_OFFSET(PerformanceCount))
  45.  
  46.     ' Elasped Performace Count
  47.     dElapsedTime = (CDBL(PerformanceCount - StartingCount)) / Frequency
  48.  
  49.     ' System Precise FileTime
  50.     qwResult = ft.dwHighDateTime
  51.     qwResult = qwResult * &H100000000
  52.     qwResult = qwResult + ft.dwLowDateTime
  53.  
  54.     PRINT CDBL(qwResult) / 10000000.0 - 11644473600.0, time_now&, dElapsedTime
  55.  
  56.     _DELAY (1)
  57. NEXT i%
  58.  
« Last Edit: March 27, 2020, 01:27:47 pm by EricE »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Hi Eric,

Have you seen this?
https://www.qb64.org/forum/index.php?topic=1598.msg108135#msg108135

But yours looks like it's focused on a files utility.