High Precision Timer using Windows API
High Precision Timer using Windows API
Private Declare PtrSafe Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Private Declare PtrSafe Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
Sub CodeTimer()
Dim StartTime As Currency, CurrentTime As Currency, TickFrequency As Currency
QueryPerformanceFrequency TickFrequency 'Get ticks per second of the PC
QueryPerformanceCounter StartTime 'Get current tick count(Used before code to time)
'Timed code here
QueryPerformanceCounter CurrentTime 'Get current tick count(Used after code to time)
MsgBox (CurrentTime - StartTime) / TickFrequency 'Returns how many seconds the timed code took to run
End Sub