Isolating terms in slow statements

Top  Previous  Next

Sometimes one runs profile and finds that the time problem is inside a tremendously long statement.  For example, I have been known to regularly run models where the objective function and some report calculation lines are well over 800 lines long containing 40 or so added terms.  Finding a timing problem in such a long statement still leaves me with the question of where is the problem.  In such cases I often temporarily deactivate part of the code using the comment inserting syntax $Ontext/$Offtext and *'s.

Namely, if a multi-term piece of code spanning lines 1182 to 1294 is slow, one could would re-execute the code, but split the term so say lines 1240 to 1294 are deactivated (surrounding them with an $Ontext - $Offtext sequence).  Then, if the remaining lines still use the bulk of the time, I would deactivate further code until the code deactivation greatly reduced the time use.  I would then know that the last section put into the text status contained the slow executing code.  I would in turn selectively activate more code until the exact problematic portion is identified.  Naturally after finding and fixing my timing problem I would reactivate all of the temporarily commented out code.