to kev
just a query i've had for a while. the help files don't specify which is best or not between these two methods. is var=array() better, or just array() on its own? is there any difference at all, as both work fine?
method 1:
if array()>number1 and array()<number2
code here
endif
method 2:
var=array()
if var>number1 and var<number2
code here
endif
thanks stevmjon
Variables have the highest precedence in PlayBASIC and are thus quickest data type to perform operations upon & between.
When in doubt, test it.
[pbcode]
Global TestForMatches=0
Dim Table(1000)
MaxTests=10000
Dim TestName$(100)
Dim results#(10)
Do
Cls 0
inc frames
; Select a point in the array to test
ArrayIndex=rnd(999)
; set test value to with a success range
if TestForMatches=0 then Table(ArrayIndex)=75
; set test value to outside of test range (bellow)
if TestForMatches=1 then Table(ArrayIndex)=5
; set test value to outside of test range (above)
if TestForMatches=2 then Table(ArrayIndex)=200
; ---------------------------
; TEST 1
; ---------------------------
test=0
t=timer()
Count=0
For lp=0 to Maxtests
if Table(ArrayIndex)>45 and Table(ArrayIndex)<100
inc count
endif
next
StoreResult(" Compare Array()>Low and Array()<High:",TEst,T)
inc test
; ---------------------------
; TEST 2
; ---------------------------
t=timer()
Count=0
For lp=0 to Maxtests
ArrayValue=Table(arrayIndex)
if ArrayValue>45 and ArrayValue<100
inc count
endif
next
StoreResult(" Compare Variable>Low and Varaible<High:",TEst,T)
inc test
; ---------------------------
; TEST 3
; ---------------------------
t=timer()
Count=0
For lp=0 to Maxtests
ArrayValue=Table(arrayIndex)
if ArrayValue>45
if ArrayValue<100
inc count
endif
endif
next
StoreResult(" Variable with Separate Low/High compares:",TEst,T)
inc test
; ---------------------------
; TEST 4
; ---------------------------
t=timer()
Count=0
For lp=0 to Maxtests
ArrayValue=Table(arrayIndex)
if ArrayValue<100
if ArrayValue>45
inc count
endif
endif
next
StoreResult(" Variable with Separate High/low compares:",TEst,T)
inc test
; ---------------------------
; TEST 5
; ---------------------------
t=timer()
Count=0
For lp=0 to Maxtests
if Range(Table(arrayIndex),45,100)
inc count
endif
next
StoreResult(" Using PB Range command:",TEst,T)
inc test
; ---------------------------
; Display results and stuff
; ---------------------------
if TestForMatches=0 then M$="Testing For Matches"
if TestForMatches=1 then M$="Testing For Fails (lower than range)"
if TestForMatches=2 then M$="Testing For Fails (greater than range)"
print "TEST MODE:"+M$
text 100,70,"Average results:"
fastestTicks#=100000
FastestIndex=0
For lp=0 to test-1
Ticks#=(results#(lp)/frames)
if FastestTicks#>Ticks#
FastestTicks#=Ticks#
FastestIndex=lp
Endif
text 100,100+(lp*35),TestName$(lp)+str$(Ticks#)
next
ink rgb(255,0,0)
text 100,100+(FastestIndex*35),TestName$(FastestIndex)+str$(FastestTicks#)
ink rgb(255,255,255)
if spacekey()
TestForMatches=mod(TestForMatches+1,3)
ClearArray results#(),0.0
frames=0
flushkeys
endif
Sync
loop
Function StoreResult(name$,ThisTEst,T)
TestName$(thisTest)=Name$
Results#(thisTest)=Results#(thisTest)+(timer()-t)
endFUnction
[/pbcode]
P.S. Please try not post questions on the forum that are addressed to me. This is not the ask Kevin forum, it's the PlayBASIC user forum.