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 15:49:13
 
 
À
20/06/2002 15:23:55
Guy Pardoe
Pardoe Development Corporation
Peterborough, New Hampshire, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00668532
Message ID:
00670808
Vues:
31
That's pretty close to my home computer configuration. I'll check to see what results I get at home and compare them with those I got at work. It will be interesting to see...
Tracy

>Hi Tracy,
>
>My current machine is an AMD Athlon 1.4Ghz. I've been using AMD chips instead of Intel for my last couple of machines. It saves a few bucks and the chips are purportedly faster than the Intel P3/4 chips with the same clock speed (GHz).
>
>Guy
>
>
>
>>What type of system are you using? I'm using a PIII 1000MHZ and i get 6.449 and 6.119 respectively. The interesting part was that when I freed up more memory to run the test, my results were 6.550 and 6.009. Only the IF/ENDIF showed an improvement while the IIF took slightly longer than before.
>>
>>tracy
>>
>>>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
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform