Announcement

Collapse
No announcement yet.

overhead

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

  • overhead

    I use the following script to test the overhead of getValue().
    The average time is 7ms when the main() is executed, which imply the overhead of getValue() is quite significant. Could someone tell me the reason and any tip to lower such overhead?


    var ko;

    function preMain() {
    setPriceStudy(false);

    /* Set the title that will appear in the study pane */
    setStudyTitle("test");
    setCursorLabelName("O");

    /* Set the label that will appear in the cursor window */
    addBand(100, PS_SOLID, 1, Color.blue);
    addBand(0, PS_SOLID, 1, Color.red);
    addBand(-100, PS_SOLID, 1, Color.blue);

    }


    function main(nInputLength, nConst) {

    if(nInputLength == null)
    nInputLength = 20;
    if(nInputLength <= 0)
    nInputLength = 20;

    for ( var i = 0; i < 10; i ++ ) {
    vHigh = getValue("High", -1, -(nInputLength+1));
    vLow = getValue("Low", -1, -(nInputLength+1));
    vClose = getValue("Close", -1, -(nInputLength+1));
    }

    return 50;
    }

  • #2
    When I ran the following I get a time of about 0.014 ms - the FOR, IF and RETURN 50 seem to add a lot of time to the routine.

    var ko;

    function preMain() {
    setPriceStudy(false);

    /* Set the title that will appear in the study pane */
    setStudyTitle("test");
    setCursorLabelName("O");

    /* Set the label that will appear in the cursor window */
    addBand(100, PS_SOLID, 1, Color.blue);
    addBand(0, PS_SOLID, 1, Color.red);
    addBand(-100, PS_SOLID, 1, Color.blue);

    }


    function main(nInputLength, nConst) {

    /*if(nInputLength == null)
    nInputLength = 20;
    if(nInputLength <= 0)
    nInputLength = 20;
    */

    //for ( var i = 0; i < 10; i ++ ) {
    vHigh = high(-1,-(nInputLength+1));

    //vHigh = getValue("High", -1, -(nInputLength+1));
    //vLow = getValue("Low", -1, -(nInputLength+1));
    //vClose = getValue("Close", -1, -(nInputLength+1));
    //}

    return;
    }

    Comment


    • #3
      Because you commented out

      nInputLength = 20;
      if(nInputLength <= 0)
      nInputLength = 20;


      vHigh = high(-1,-(nInputLength+1)) won't be executed as I want because nInputLength is null

      Comment


      • #4
        my mistake, I get 0.16 with this

        var ko;

        function preMain() {
        setPriceStudy(false);

        /* Set the title that will appear in the study pane */
        setStudyTitle("test");
        setCursorLabelName("O");

        /* Set the label that will appear in the cursor window */
        addBand(100, PS_SOLID, 1, Color.blue);
        addBand(0, PS_SOLID, 1, Color.red);
        addBand(-100, PS_SOLID, 1, Color.blue);

        }


        function main(nInputLength, nConst) {

        /*if(nInputLength == null)
        nInputLength = 20;
        if(nInputLength <= 0)
        nInputLength = 20;
        */

        //for ( var i = 0; i < 10; i ++ ) {
        vHigh = high(-1,-(20+1));

        //vHigh = getValue("High", -1, -(nInputLength+1));
        //vLow = getValue("Low", -1, -(nInputLength+1));
        //vClose = getValue("Close", -1, -(nInputLength+1));
        //}

        return;
        }

        Comment

        Working...
        X