Hi George,
For a million loops, something like 1.4 seconds versus 1.2 seconds, consistently and with nothing else running.
I think I mentioned this earlier ... I have known IF...ENDIF to be faster for quite some time now. I thought it was common wisdom and I was surprised when I saw messages stating IIF was faster. So I just took a couple of minutes and whipped up this example.
You can try the code yourself for further validation.
Bottom line ... I have no inside knowledge here, but I have always believed that for all versions ... as long as IIF has been around, IF...ENDIF has been faster.
Guy
>>Kirk,
>>
>>I see that others have posted and said that IIF is faster than IF...ENDIF.
>>
>>I disagree!
>>
>>I remember testing this in the past and I've always found IF...ENDIF to be faster. I just ran another test using your example and as I expected, I found IF...ENDIF to be faster.
>>
>>Here's what I did:
>>
>>#DEFINE MAXLOOPS 1000000
>>ldStartOn = DATE()
>>lnStart = SECONDS()
>>FOR x = 1 TO MAXLOOPS
>> ldStartOn = ldStartOn + IIF(VARTYPE(ldStartOn)=[D],1,86400)
>>ENDFOR
>>lnEnd = SECONDS()
>>MESSAGEBOX('IIF: ' + TRANSFORM(lnEnd-lnStart))
>>
>>
>>lnStart = SECONDS()
>>FOR x = 1 TO MAXLOOPS
>> IF VARTYPE(ldStartOn)=[D]
>> ldStartOn=ldStartOn+1
>> ELSE
>> ldStartOn=ldStartOn+86400
>> ENDIF
>>ENDFOR
>>lnEnd = SECONDS()
>>MESSAGEBOX('IF-ENDIF: ' + TRANSFORM(lnEnd-lnStart))
>>
>>
>Guy,
>
>Hmmm...I could've sworn that at one time I read that IIF() was faster. Maybe it was "conventional wisdom" that no longer applies.
>
>I do, however, have a couple of questions.
>
>First, what were the actual results?
>
>Second, how many times did you run the test and were the results consistent?
>
>Third, did you have anything else other than VFP running at the time?