Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Which Should I Use IF/ENDIF or IIF
Message
From
21/06/2002 03:46:26
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
20/06/2002 08:17:49
Guy Pardoe
Pardoe Development Corporation
Peterborough, New Hampshire, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00668532
Message ID:
00670932
Views:
20
Hi Guy,
Yes really these tests don't matter. I honestly take different approaches for bottlenecks as need arises. Over 100 times absolutely not worth to test if/iif.
Yes it's academic :) and honestly again if that were millions of loops again if/iif would be the last thing I'd care for a bottleneck check.
But theoritically speaking my tests make a difference and show iif is faster :) I didn't just think and wrote but ran the test with even more loops - multiple times :)

PS: Nice computer you have :) Mine is still Athlon 650Mhz.
Cetin

>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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform