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)
Printable View
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)
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.Quote:
Originally Posted by Doogle
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
Thanks to both of you Doogle and PraDeep for answering my question!:cool:
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.