Announcement

Collapse
No announcement yet.

Slow execution

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Slow execution

    This code takes 10 minutes to calculate on ~2800 bars:


    /************************************************** **************************************************
    Sine-weighted Moving Average
    ************************************************** ************************************************** */

    function preMain() {
    setPriceStudy(true);
    setDefaultBarThickness(2);
    setDefaultBarFgColor(Color.green);
    }

    var sin1 = Math.sin(Math.PI/6);
    var sin2 = Math.sin(Math.PI/3);
    var sin3 = Math.sin(Math.PI/2);
    var sin4 = Math.sin(Math.PI*2/3);
    var sin5 = Math.sin(Math.PI*5/6);

    function main() {

    var S1 = 0.0;
    var S2 = 0.0;
    var S3 = 0.0;
    var S4 = 0.0;
    var S5 = 0.0;
    var Num = 0.0;
    var Dem = 0.0;

    S1 = sin1*close(0,1);
    S2 = sin2*close(-1,1);
    S3 = sin3*close(-2,1);
    S4 = sin4*close(-3,1);
    S5 = sin5*close(-4,1);
    Num = S1+S2+S3+S4+S5;
    Den = sin1+sin2+sin3+sin4+sin5;

    return Num/Den;

    }

    but only 3 seconds in Tradestation (using EasyLanguage version).

    ?????

    atlas

  • #2
    Re: Slow Execution

    Figured it out:

    DebugPrint's kill execution time.

    Comment


    • #3
      600 milliseconds

      Hi Atlas,

      You say it took 10 minutes to compute that EFS using eSignal but only 3 seconds using TradeStation?

      Below is a link to a picture. I copied your formula right into eSignal, added it to a chart with 2800 bars. It shows that for 2800 bars, it took a total of 600 milliseconds to run that formula. With an average of 0.2142 milliseconds per call to the function "main". I added that formula to the chart and it plotted almost instantaneously.

      Could you tell us a little more. 600 milliseconds vs 10 minutes -- seams something might be amiss...


      Matt Gundersen

      Comment


      • #4
        Figured it out:
        DebugPrint's kill execution time.
        Yes, DebugPrint and debugPrintln are both killers. I had a fairly simple formula that was using way more CPU than some of my really complex ones - all due to having some debug in my simple formula.

        Never keep debug statements in production code (unless it is to print an error before bombing out).
        Garth

        Comment

        Working...
        X