Date: 02-16-2022
Return to Index
created by gbSnippets
'Applications often need to compute elapsed time between two events, for reasons
'such as comparing the time it takes two different algorithms to execute. The
'four basic approaches are:
'TIMER (PowerBASIC) - elapsed time since midnight
'TIX (PowerBASIC) - CPU cycles since last use of TIX
'GetTickCount() API
'QueryPerformanceCount() API
'For absolute accuracy in comparing time to execute events, TIX and QueryPerformanceCounter
'are the best choices. With QueryPerformanceCounter you can convert to time, so it is more
'flexible. Timer and GetTickCount are easier to use, but less accurate. For simple convenience
'and reasonable accuracy on longer intervals, programmers often rely on GetTickCount.
'Primary Code:
Local T As Quad
Tix T 'sets T to current CPU cycle counter value
'---------------------------------------
'... do something
'---------------------------------------
Tix End T 'set T to elapsed CPU cycles since last use of Tix
? "TIX: " + str$(T)
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Global qFreq, qStart, qStop AS QUAD
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Test", 20,10,120,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case 100 : SpeedTest
End Select
End Select
End Function
Sub SpeedTest
Local T As Quad
Tix T
'---------------------------------------
'.... do something here
'---------------------------------------
Tix T 'is the DELTA CPU cycles
? "TIX: " + str$(T)
End Sub
'gbs_00391
'Date: 03-06-2012
http://www.garybeene.com/sw/gbsnippets.htm