Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Which Should I Use IF/ENDIF or IIF
Message
De
20/06/2002 08:17:49
Guy Pardoe
Pardoe Development Corporation
Peterborough, New Hampshire, États-Unis
 
 
À
19/06/2002 13:24:20
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00668532
Message ID:
00670544
Vues:
27
Hi Cetin,

I expect that most of the time, these speed/performance questions really don't matter. I think the original message on this thread indicated that the code would be in a loop that would execute over 100 times (or something like that). It could take a few million loops before any human being noticed a difference.

As I mentioned in another message on this thread, it's academic. I admit that others have apparently run tests that show IIF() performing better than IF...ENDIF, at least some of the time. It's just that I have never gotten that result. I have always found IF...ENDIF to be faster. But I don't even bother with performance issues like this except where I am processing a massive amount of loops.

Theorectically speaking, I don't think your examples below should make a difference. As long as you're testing the identical condition/expression with both 'IF' formats and executing the same variable assignment, I would expect to see consistent performance in the tests.

For a sheer speed test on the function itself, you could do a comparison like this:
#DEFINE MAXLOOPS 10000000
y=0
lnStart = SECONDS()
FOR x = 1 TO MAXLOOPS
	IIF(.T.,y=1,y=0)
ENDFOR
lnEnd = SECONDS()
MESSAGEBOX('IIF: ' + TRANSFORM(lnEnd-lnStart))

y=0
lnStart = SECONDS()
FOR x = 1 TO MAXLOOPS
	IF .T.
		y=1
	ELSE
		y=0
	ENDIF
ENDFOR
lnEnd = SECONDS()
MESSAGEBOX('IF-ENDIF: ' + TRANSFORM(lnEnd-lnStart))
This simplifies the logic and focuses on performance of one method over the other. As a side note, I get IF...ENDIF showing the faster result when I test this. I bumped this up to 10,000,000 loops and typically get 4.7 seconds versus 4.3 seconds.

If I had more time, I'd do some experimenting and try to understand why some people got IIF() performing better in some conditions. But we probably all have more important things to do. :)

Guy



>Guy,
>I don't agree nor disagree :) I've been always under impression in fox there is never one simple test that shows that something is absolutely right, especially speed tests.
>What if I slightly change your iif() test portion to read :
>
>ldStartOn = IIF(VARTYPE(ldStartOn)=[D],1,86400)+ldStartOn
>
>or :
>
>ldStartOn = IIF(VARTYPE(ldStartOn)=[D],ldStartOn+1,ldStartOn+86400)
>
>:)
>Cetin
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform