QPX( N=0 ) { ; Wrapper for QueryPerformanceCounter()by SKAN | CD: 06/Dec/2009
Static F,A,Q,P,X ; www.autohotkey.com/forum/viewtopic.php?t=52083 | LM: 10/Dec/2009
If ( N && !P )
Return DllCall("QueryPerformanceFrequency",Int64P,F) + (X:=A:=0) + DllCall("QueryPerformanceCounter",Int64P,P)
DllCall("QueryPerformanceCounter",Int64P,Q), A:=A+Q-P, P:=Q, X:=X+1
Return ( N && X=N ) ? (X:=X-1)<<64 : ( N=0 && (R:=A/X/F) ) ? ( R + (A:=P:=X:=0) ) : 1
} Returns value will be in Seconds like 1.234567,
Where, Red is Seconds, Green is Milliseconds and Blue is Thousandth of Millisecond
Example:
SetBatchLines -1 ;;** Basic Usage ** QPX( True ) ; Initialise Counter Sleep 1000 Ti := QPX( False ) ; Retrieve Time consumed ( & reset internal vars ) MsgBox, 0, Sleep 1000, %Ti% seconds ;;** Extended Usage ** While QPX( 1000 ) ; Loops 1000 times and keeps internal track of the total time Tooltip %A_Index% Ti := QPX() ; Retrieve Avg time consumed per iteration ( & reset internal vars ) MsgBox, 0, Avg Time Taken for ToolTip, %Ti% Seconds / Iteration
Delay()
MsgBox, % Delay( 0.008 ) ; Delay for 8ms
Delay( D=0.001 ) { ; High Resolution Delay ( High CPU Usage ) by SKAN | CD: 13/Jun/2009
Static F ; www.autohotkey.com/forum/viewtopic.php?t=52083 | LM: 13/Jun/2009
Critical
F ? F : DllCall( "QueryPerformanceFrequency", Int64P,F )
DllCall( "QueryPerformanceCounter", Int64P,pTick ), cTick := pTick
While( ( (Tick:=(pTick-cTick)/F)) <D ) {
DllCall( "QueryPerformanceCounter", Int64P,pTick )
Sleep -1
}
Return Round( Tick,3 )
}




