Page 1 of 1

Nested IFs or use Contine. What gives better performance?

Posted: Thu Apr 28, 2016 2:25 pm
by Bakkone
Hi all,

Im rebuilding some stuff at work and need some advice on what is best from a performance perspective. This cube is going to get big because of an "advanced" idea on how things should be organized.

Consider the two examples:

Example 1:

Code: Select all

['Value'] = N:
     IF( !Period <= ['PeriodBreak1'],
          ['Value1'],
               IF( !Period <= ['PeriodBreak2'],
                    ['Value2'],
                         IF( !Period <= ['PeriodBreak3'],
                              ['Value3'], ['Value4']
                         )
               )
     ) ;

Example 2:

Code: Select all

['Value'] = N:
     IF( !Period <= ['PeriodBreak1'],
          ['Value1'],
          CONTINUE
     ) ;

['Value'] = N:
     IF( !Period <= ['PeriodBreak2'],
          ['Value2'],
          CONTINUE
     ) ;

['Value'] = N:
     IF( !Period <= ['PeriodBreak3'],
          ['Value3'],
          ['Value4']
     ) ;
Currently the new rebuilt model is small and I can't notice any difference in performance. I do however have other similar parts of the solution that is built more like Example 2. Im not that experienced but I find those parts of the model to have surprisingly fast performance considering the size. That is compared to other stuff I made like Example 1. But i could be imagining things, and there are other factors that affect performance.

So does anyone know if Example 1 or Example 2 is better from a performance perspective? Someone thats been doing this a lot longer than I have? I looked around for a best practice but found none.

Regards
David

Re: Nested IFs or use Contine. What gives better performance?

Posted: Fri Apr 29, 2016 5:54 am
by BariAbdul
Personally,I would prefer second option ,Just to reduce no of conditional tests and IF statements.Thanks

Re: Nested IFs or use Contine. What gives better performance?

Posted: Fri Apr 29, 2016 12:26 pm
by qml
There shouldn't be any measurable performance difference between these two approaches, because in both the engine needs to perform the same number of tests to produce every requested figure.

I prefer the nested IFs because of calculation traceability. For me it is easier to read and decode when a calculation is implemented in a single formula. If it's spread across multiple formulas, especially if they sit in different areas of a large rule file, it can become harder to debug, maintain or change. Of course, there is also a limit to how many nested IFs in a single formula can be reasonably taken in and decoded. I've never had to work with more than about 4 (which means 16 different outcomes), but if I absolutely had to have more I would consider breaking them down using CONTINUE.

The bottom line is that there isn't a clear best practice because it is largely an area of personal preference and circumstance. From my experience performance does not come into play with this particular question.

Re: Nested IFs or use Contine. What gives better performance?

Posted: Tue May 03, 2016 5:52 am
by Bakkone
Thanks for your replies. I sent the question to IBMs product team as well. I will update you if I get a reply.

I prefer the nested IFs as well as I can then clearly see how a measure is calculated, without having to look in the entire rule-file for variants.

I do use continue at the top of a rule file if I have any conditional calculations where I want to opt out large chunks of the cube from calculations. Say for example that all historical values are supposed to be STET, or inactive periods or something.

Regards
David