topic Re: Optimal if statements in Anaplan Platform
https://community.anaplan.com/t5/Anaplan-Platform/Optimal-if-statements/m-p/75873#M15726
<UL><LI>If you need to get a maximum of two line items, is it more efficient to use an if statement "if a > b then a else b" or to use the max formula "max(a,b)" - max(a,b) , an inbuilt formula is always better than a conditional statement</LI><LI>Is there any performance difference in "if x<y then a else b" vs “if y<x then b then a” (in case there is only one if statement, in case there is a nested if statement then the most common case should be put first) - I dont think so, they both look same </LI><LI>In some languages the performance is better to have "boolean * number" instead of having an if statement "if.boolean then number else 0".<BR />In anaplan you cannot apply this, but we could replace the boolean as number with only 0/1's.<BR />Given the planual "Use conditionals to stop unnecessary calculations", it is probably still better to have the if statement? - Yes right, so if you have a zero you will not do any calculation , whereas in case of 1 you will do the calculation. Hence, you will save on several calculations</LI></UL>Thu, 02 Jul 2020 07:58:09 GMTYash12020-07-02T07:58:09ZOptimal if statements
https://community.anaplan.com/t5/Anaplan-Platform/Optimal-if-statements/m-p/75866#M15724
<P>I want to make sure that I optimize my if statements, hence some question</P><P> </P><UL><LI>If you need to get a maximum of two line items, is it more efficient to use an if statement "if a > b then a else b" or to use the max formula "max(a,b)"</LI><LI>Is there any performance difference in "if x<y then a else b" vs “if y<x then b then a” (in case there is only one if statement, in case there is a nested if statement then the most common case should be put first)</LI><LI>In some languages the performance is better to have "boolean * number" instead of having an if statement "if.boolean then number else 0".<BR />In anaplan you cannot apply this, but we could replace the boolean as number with only 0/1's.<BR />Given the planual "Use conditionals to stop unnecessary calculations", it is probably still better to have the if statement?</LI></UL>Thu, 02 Jul 2020 06:31:18 GMThttps://community.anaplan.com/t5/Anaplan-Platform/Optimal-if-statements/m-p/75866#M15724Lander.Bruneel2020-07-02T06:31:18ZRe: Optimal if statements
https://community.anaplan.com/t5/Anaplan-Platform/Optimal-if-statements/m-p/75873#M15726
<UL><LI>If you need to get a maximum of two line items, is it more efficient to use an if statement "if a > b then a else b" or to use the max formula "max(a,b)" - max(a,b) , an inbuilt formula is always better than a conditional statement</LI><LI>Is there any performance difference in "if x<y then a else b" vs “if y<x then b then a” (in case there is only one if statement, in case there is a nested if statement then the most common case should be put first) - I dont think so, they both look same </LI><LI>In some languages the performance is better to have "boolean * number" instead of having an if statement "if.boolean then number else 0".<BR />In anaplan you cannot apply this, but we could replace the boolean as number with only 0/1's.<BR />Given the planual "Use conditionals to stop unnecessary calculations", it is probably still better to have the if statement? - Yes right, so if you have a zero you will not do any calculation , whereas in case of 1 you will do the calculation. Hence, you will save on several calculations</LI></UL>Thu, 02 Jul 2020 07:58:09 GMThttps://community.anaplan.com/t5/Anaplan-Platform/Optimal-if-statements/m-p/75873#M15726Yash12020-07-02T07:58:09ZRe: Optimal if statements
https://community.anaplan.com/t5/Anaplan-Platform/Optimal-if-statements/m-p/75911#M15741
<P>The conditional operations IF, AND and OR all can improve performance if they allow expensive calculations to be skipped. However they impose their own penalty in the form of instruction pipeline flushes; although modern CPUs will speculatively issue instructions based on branch prediction, for trivial operations it may be more performant if refactoring is possible. In many cases the business logic embodied by the formula requires these decision points however. And let's not abandon readability - it is better to get the right answer slightly more slowly than the wrong answer slightly more quickly. The only advice I'd give in addition to nested IFs is that if a Boolean subexpression (A) is more expensive to calculate than (B) then "(B) AND (A)" is probably better than "(A) AND (B)" and likewise for OR - especially if for AND there are plenty of FALSE evaluations on the left hand side (or TRUE for OR).</P>Thu, 02 Jul 2020 15:09:26 GMThttps://community.anaplan.com/t5/Anaplan-Platform/Optimal-if-statements/m-p/75911#M15741ben_speight2020-07-02T15:09:26Z