I'd like your help
Can you try the piece of code below and tell me what the msgbox's tells you (simply press Ctrl+c when the msgbox is displayed to copy the text in it)
I'm trying to find out if one method of determining if an integer is between two integers (inclusive) is faster then the other
Code: Select all
#Persistent
#SingleInstance force
SetBatchLines, -1
f1:: ; speed testing fastest way to determine if an integer is between two integers (inclusive)
time1:=time2:=inrange:=inrange2:="" ; clear variables
lower := 50
upper := 100
InputBox, number, time test, Please Enter a number `n`ni.e 88
Y := number-lower
Y := NumGet( NumPut( Y, Var:="ABCD" )-4, 0,"UInt" ) ; Convert Y to unSigned Integer
Q := (upper-lower)+1
QPX( True ) ; Initialise Counter
loop 2073600 ; loop 1920x1080 times
if (Y < Q)
inrange := true
time1 := QPX( false ) ; Retrieve Time consumed ( & reset internal vars )
QPX( True ) ; Initialise Counter
loop 2073600 ; loop 1920x1080 times
if (number >= lower && number <= upper)
inrange2 := true
time2 := QPX( false ) ; Retrieve Time consumed ( & reset internal vars )
msgbox % "First check method:`nIf number " number " is between " lower "-" upper " is " (inrange?"true":"false") " and it took " time1 "`n`nSecond check method:`nIf number " number " is between " lower "-" upper " is " (inrange2?"true":"false") " and it took " time2
return
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
}
Please let me know what you find
PS: Also let me know if you find something that's not working or is off with the way i'm doing this...