To Compare reletive speed of different versions of program code. or some other thing you want to compare.
It is not a replacement for Waitable Timer or Realtime time stamp.
API function QueryPerformanceCounter() is easy enough to use, but requires you to provide two QUADs and code for a subtraction. Is presented as an #INCLUDE file because FASTPROC can not use COMMON or EXPORT, which is needed to make an SLL or DLL of it. The demo, below, compares using the API function directly with the FASTPROCs in this include file. These FASTPROCs "hide" the second QUAD, its pointer, and the subtraction to operate like TIX. They are more stable than TIX, and better resolution than GetTickCount() or GetTickCount64(), due use of QueryPerformanceCounter().
'HR_Interval.inc 'A stable high resolution interval counter. ' 'This version of the API DECLARE uses BYVAL for the parameter instead of 'BYREF, the default when not specified. Else the user would need to add BYVAL 'in the calls to the FASTPROCs (less "hidden"). declare function QueryPerformanceCounterFP lib "Kernel32.dll" _ alias "QueryPerformanceCounter" (byval pPerformanceCount as dword) as long global gEndCountOfHRInterval as quad global gpEndCountOfHRInterval as dword ' fastproc HR_Interval (byval pCnt as long) gpEndCountOfHRInterval = varptr(gEndCountOfHRInterval) QueryPerformanceCounterFP pCnt end fastproc fastproc End_HR_Interval (byval pCnt as long) QueryPerformanceCounterFP gpEndCountOfHRInterval poke quad, pCnt, peek(quad, gpEndCountOfHRInterval) - peek(quad, pCnt) end fastproc
Shows both direct use of API function, and use of FASTPROCs.
#compile exe #dim all #if %pb_cc32 'Ignored in PBWin, stops unneeded console in PBCC. #console off #endif 'Copied from \WinAPI\WinBase.inc so it can be seen here. declare function QueryPerformanceCounter lib "Kernel32.dll" _ alias "QueryPerformanceCounter" (lpPerformanceCount as quad) as long function pbmain () as long local Interval, QTmp as quad local hTxt as dword txt.window("Demo High Res Interval Timer", 100, 100, 25, 50) to hTxt txt.print "Use QueryPerformanceCounter directly." sleep 0 'start interval count on new time slice. QueryPerformanceCounter Interval sleep 100 'a low res interval to get a count of QueryPerformanceCounter QTmp Interval = QTmp - Interval txt.print dec$(Interval) txt.print txt.print "Wrap QueryPerformanceCounter in FASTPROCs." #include "HR_Interval.inc" sleep 0 'start interval count on new time slice. HR_Interval (varptr(Interval)) 'Or VARPTR could be used for a variable before the call. Would be especially 'useful if multiple intervals are being checked. sleep 100 'a low res interval to get a count of End_HR_Interval (varptr(Interval)) txt.print dec$(Interval) txt.print txt.print "Any key to exit." txt.waitkey$ end function
Created on 13 March 2023.
To
Domain Home. | To Dale's Notebook index. | To Programs index. |