|
-
Jan 31st, 2008, 02:59 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] IIF Statement
Would you say these two produce the same result, all the time, when testing for booleans?
blnResult = (CDate(strDate) > Now)
blnResult = IIf(CDate(strDate) > Now, True, False)
Last edited by Liquid Metal; Jan 31st, 2008 at 12:33 PM.
I'll Be Back!
T-1000
Microsoft .Net 2005
Microsoft Visual Basic 6
Prefer using API
-
Jan 31st, 2008, 03:34 AM
#2
Re: IIF Statement
I would say that they're functionally equivalent.
(CDate(strDate) > Now) will return True or False as will the IIf statement.
Perhaps the IIf statement is a little more obvious, to the reader, about what's being tested, but that's a matter of interpretation.
Just out of interest I timed the two. Executing a 1,000,000 of each resulted in the following times on my machine:
Code:
binResult = (CDate(strDate) > Now) - about 7,500 mS
binResult = IIf(CDate(strDate) > Now, True, False) - about 8,300 mS
Any particular reason you're asking?
-
Jan 31st, 2008, 05:34 AM
#3
Re: IIF Statement
 Originally Posted by Doogle
I would say that they're functionally equivalent.
(CDate(strDate) > Now) will return True or False as will the IIf statement.
Perhaps the IIf statement is a little more obvious, to the reader, about what's being tested, but that's a matter of interpretation.
Just out of interest I timed the two. Executing a 1,000,000 of each resulted in the following times on my machine:
Code:
binResult = (CDate(strDate) > Now) - about 7,500 mS
binResult = IIf(CDate(strDate) > Now, True, False) - about 8,300 mS
Any particular reason you're asking?
IIF statement would obviously be slow because it is a function and would evaluate all its input parameters irrespective of it's type.
Besides this, the overhead of transfer of control from and to the function would also be significant in this situation as the first statement is just a simple mathematical comparison while the other one is a function call.
Pradeep
Last edited by Pradeep1210; Jan 31st, 2008 at 06:59 AM.
-
Jan 31st, 2008, 12:32 PM
#4
Thread Starter
Frenzied Member
Re: IIF Statement
Thanks to both of you Doogle and PraDeep for answering my question!
Doogle, also thanks for taking it to another level and did that speed testing for me. No particular reason why I want to know but I just like to improve and improve on writing efficient code. That is all.
I'll Be Back!
T-1000
Microsoft .Net 2005
Microsoft Visual Basic 6
Prefer using API
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|