I've dramatically improved the speed performance of the IIF macro, and managed to do away with the need for Val(Str()) in the process while preserving the float evaluation integrity. I've pasted the change directly into Idle's time test example below to demonstrate. It's not perfect yet but it's much, much faster than before.
Code: Select all
Global tt.TIMECAPS
timeGetDevCaps_(@tt, SizeOf(TIMECAPS))
timeBeginPeriod_(tt\wPeriodMin)
Procedure.s IIFEval(expr,y$,n$)
If expr=1:ProcedureReturn y$
Else:ProcedureReturn n$
EndIf
EndProcedure
Procedure IIFEvaln(expr,y,n)
If expr=1
ProcedureReturn y
Else
ProcedureReturn n
EndIf
EndProcedure
Macro IIFn(expr,y,n)
IIFEvaln(1-(1 And Not(expr)),y,n)
EndMacro
Macro IIF(expr,y,n)
IIFEval(1-(1 And Not(expr)),y,n)
EndMacro
Debug IIF(5.5>5.4,"yes","no")
Debug IIF(5.5>5.6,"yes","no")
Debug IIF(5.5=5.5,"yes","no")
Debug IIFn(5.5>5.7,200,100)
Debug iifn(5.5>5.4 And 5>3,200,100)
lp = 10000000
st = GetTickCount_()
For a = 1 To lp
x= IIFn(5>7,200,100)
Next
et1.f = (GetTickCount_() - st) / lp
st = GetTickCount_()
For a = 1 To lp
If 5 > 7
x = 200
Else
x = 100
EndIf
Next
et2.f = (GetTickCount_() - st) / lp
MessageRequester("test", "iif " + StrF(et1,6) + " if " + StrF(et2,6))
Also my original crude time test:
Code: Select all
e=ElapsedMilliseconds()
For x=1 To 100000000
z=1-(1 And Not(5.5>5.3))
Next x
MessageRequester("Test result",Str(ElapsedMilliseconds()-e))
...now for me returns just under 300 milliseconds for one hundred million cycles, as opposed to 3250 milliseconds before. About a 10x improvement in this (admittedly crude and incomplete) test example.