Author |
Message
|
ghoshly |
Posted: Mon Aug 12, 2013 7:33 am Post subject: Performance benefit between CARDINALITY and EXISTS |
|
|
Partisan
Joined: 10 Jan 2008 Posts: 333
|
Hello,
We say that cardinality function does not has good performance. What about EXISTS ?
Option a. IF CARDINALITY(RF_Temp.GetInfo[]) > 0 THEN
Option b. IF EXISTS(RF_Temp.GetInfo[]) THEN
Is Option b is much faster, or both are similar ??
WMB 8.0.0.2 |
|
Back to top |
|
 |
lancelotlinc |
Posted: Mon Aug 12, 2013 7:36 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
When you time each, what are your results?
Why post a question when you can measure your own performance and draw your own conclusions in about ten minutes?
We don't have access to the rest of your code, so we cannot run these tests.
Only you can. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
McueMart |
Posted: Mon Aug 12, 2013 7:59 am Post subject: |
|
|
 Chevalier
Joined: 29 Nov 2011 Posts: 490 Location: UK...somewhere
|
I would guess the performance of CARDINALITY would vary based on the number of elements in the GetInfo[], whereas I would guess the EXISTS wouldn't. If there is only 1 or 2 elements in your array you would probably barely notice a difference.
Best practice is to go with EXISTS though. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Aug 12, 2013 8:02 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
I'd guess that there's never a reason to count all of the children of a tree just to find out if there's at least one child of the tree. |
|
Back to top |
|
 |
kimbert |
Posted: Mon Aug 12, 2013 1:52 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
mqjeff is correct. The info center explicitly says that EXISTS is faster than CARDINALITY : http://publib.boulder.ibm.com/infocenter/wmbhelp/v7r0m0/topic/com.ibm.etools.mft.doc/ak05535_.htm
There is one non-obvious detail, though. Suppose that you want to efficiently test whether the (large) complex element 'elementWithManyChildren' exists. The obvious test is
Code: |
IF EXISTS(InputRoot.XMLNSC.rootElement.elementWithManyChildren) ... |
but actually this can be much faster:
Code: |
IF EXISTS(InputRoot.XMLNSC.rootElement.elementWithManyChildren.*[1]) ... |
The first parses all of the large, complex tag. The second only parses its first child. This behaviour is technically correct - 'elementWithManyChildren' cannot really be said to 'exist' unless all of it can be parsed successfully. But if Parse Timing is 'On Demand' then testing for the existence of the first child might be much faster. _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
ghoshly |
Posted: Mon Aug 12, 2013 5:51 pm Post subject: Thank you.... |
|
|
Partisan
Joined: 10 Jan 2008 Posts: 333
|
Thank you Kimbert and all for the detailed explanation. It really helps. |
|
Back to top |
|
 |
|