Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Which Should I Use IF/ENDIF or IIF
Message
De
19/06/2002 13:24:20
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
14/06/2002 13:26:29
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:
00670223
Vues:
17
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




>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
Ç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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform