Dennis,
I see your results went back and forth, depending on version and use of the debug window.
I just tried the same code a few times in VFP6.0 sp3 and got about 1.4 seconds IIF, and 1.2 seconds IN...ENDIF.
I wonder what's causing the difference between our two machines on VFP6.
I doubt it's the service pack. I would guess that we might have some other environment setting that's different.
Guy
>I've attended optimization sessions at various conferences and all of the demos have shown IIF to be faster than IF...ENDIF.
>
>I tried your test with VFP 6.0 SP5 and Win2000 and got the following results.
>
> Trial: 1 2 3 4 5 6 7 8
> IIF: 76.83 63.56 67.44 64.65 4.096 4.101 4.501 4.515
>IF...ENDIF: 124.66 122.39 111.58 112.22 4.226 4.258 4.503 4.556
>
>After the 4th trial I discovered that I had the Debug window open, that is why the tests got faster.
>
>I also tried your test with VFP 7.0 and Win2000 and got the following results.
>
> Trial: 1 2 3 4 5 6 7
> IIF: 3.772 4.117 3.970 6.259 6.311 6.780 6.211
>IF...ENDIF: 3.280 3.502 3.517 7.953 7.799 7.697 7.467
>
>After trial 3 I opened the VFP 7.0 Debug window and after trial 6 I closed it.
>
>
>>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
>>
>>
>>
>>
>>
>>>I have a fairly large module that contains a search routine that consists of a series of Loops inside loops, inside loops. Within the loops I have serveral places where I do comparisons such as:
>>>
>>>
>>>IF VARTYPE(ldStartOn)=[D]
>>> ldStartOn=ldStartOn+1
>>>ELSE
>>> ldStartOn=ldStartOn+86400
>>>ENDIF
>>>
>>>
>>>I like the code format for readability of the IF/ELSE/ENDIF, but I'm wondering if I'm doing myself a disservice in terms of speed. This code could be replaced with a IIF(). Since this module I'm looking at runs potientially 100+ times before it exits, I thought I might want to find out which way was better in terms of speed.
>>>
>>>Thanks for any input.
>>>
>>>Kirk