Announcement

Collapse
No announcement yet.

CPU utilization with efs()

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • CPU utilization with efs()

    It appears that I am taking a pretty big hit in CPU utilization when an efs() is called; especially the first time. I think part of the problem is that the efs() returns an array and a lot of time is spent getting (calculating) the various individual array values.

    efslib:
    PHP Code:
    //Define the DynamicSuppRess indicator
    //Note:  it takes 2 functions to turn a KP indicator into a serial object
    //Note: DynamicSuppRess returns an array.  must use efs()
    function KPDynamicSR(symbolinterval) {
        if(
    symbol == nullsymbol getSymbol();
        if(
    interval == nullinterval getInterval();
        var 
    vSymbol symbol "," interval
        
    return new Array(efs(KP2Path "KPDynamicSuppRess.efs",0,symvSymbol)), efs(KP2Path "KPDynamicSuppRess.efs",1,symvSymbol)), efs(KP2Path "KPDynamicSuppRess.efs",2,symvSymbol)) ); 
    indicator;
    PHP Code:
    function main(fpSymbolfpIntervalfpPT1fpPS1fpThick1fpColor1fpPT2fpPS2fpThick2fpColor2fpPT3fpPS3fpThick3fpColor3fpPVar)
    {
        
    // one time initialization
        
    if(bInit == false){
            if(
    fpSymbol == nullfpSymbol getSymbol();
            if(
    fpInterval == nullfpInterval getInterval();
            
    setCursorLabelName("ESKPDYNAMICSUPPRESSB_Mean " +fpSymbol "(" fpInterval ")",0);
            
    setCursorLabelName("ESKPDYNAMICSUPPRESSB_Ress " +fpSymbol "(" fpInterval ")",1);
            
    setCursorLabelName("ESKPDYNAMICSUPPRESSB_Supp " +fpSymbol "(" fpInterval ")",2);
            
    //set the Plot Type for the 1st variable
            
    switch(fpPT1)    {
                case 
    "Line":
                   
    setPlotType(PLOTTYPE_LINE,0);
                   break;
                case 
    "Dot":
                    
    setPlotType(PLOTTYPE_DOT,0);
                    break;
                case 
    "SquareWave":
                    
    setPlotType(PLOTTYPE_SQUAREWAVE,0);
                    break;
                case 
    "Histogram":
                    
    setPlotType(PLOTTYPE_HISTOGRAM,0);
                    break;
                case 
    "FlatLines":
                    
    setPlotType(PLOTTYPE_FLATLINES,0);
                    break;
                case 
    "InstantColorLine":
                    
    setPlotType(PLOTTYPE_INSTANTCOLORLINE,0);
                    break;
            }
            
    //Set the Plot Style for the 1st variable
            
    switch(fpPS1)    {
                case 
    "Solid":
                    
    setDefaultBarStyle(PS_SOLID,0);
                   break;
                case 
    "Dot":
                    
    setDefaultBarStyle(PS_DOT,0);
                    break;
                case 
    "Dash":
                    
    setDefaultBarStyle(PS_DASH,0);
                    break;
                case 
    "DashDot":
                    
    setDefaultBarStyle(PS_DASHDOT,0);
                    break;
                case 
    "DashDotDot":
                    
    setDefaultBarStyle(PS_DASHDOTDOT,0);
                    break;
            }
            
    //set the Plot Type for the 2nd variable
            
    switch(fpPT2)    {
                case 
    "Line":
                   
    setPlotType(PLOTTYPE_LINE,1);
                   break;
                case 
    "Dot":
                    
    setPlotType(PLOTTYPE_DOT,1);
                    break;
                case 
    "SquareWave":
                    
    setPlotType(PLOTTYPE_SQUAREWAVE,1);
                    break;
                case 
    "Histogram":
                    
    setPlotType(PLOTTYPE_HISTOGRAM,1);
                    break;
                case 
    "FlatLines":
                    
    setPlotType(PLOTTYPE_FLATLINES,1);
                    break;
                case 
    "InstantColorLine":
                    
    setPlotType(PLOTTYPE_INSTANTCOLORLINE,1);
                    break;
            }
            
    //Set the Plot Style for the 2nd variable
            
    switch(fpPS2)    {
                case 
    "Solid":
                    
    setDefaultBarStyle(PS_SOLID,1);
                   break;
                case 
    "Dot":
                    
    setDefaultBarStyle(PS_DOT,1);
                    break;
                case 
    "Dash":
                    
    setDefaultBarStyle(PS_DASH,1);
                    break;
                case 
    "DashDot":
                    
    setDefaultBarStyle(PS_DASHDOT,1);
                    break;
                case 
    "DashDotDot":
                    
    setDefaultBarStyle(PS_DASHDOTDOT,1);
                    break;
            } 
            
    //set the Plot Type for the 3rd variable
            
    switch(fpPT3)    {
                case 
    "Line":
                   
    setPlotType(PLOTTYPE_LINE,2);
                   break;
                case 
    "Dot":
                    
    setPlotType(PLOTTYPE_DOT,2);
                    break;
                case 
    "SquareWave":
                    
    setPlotType(PLOTTYPE_SQUAREWAVE,2);
                    break;
                case 
    "Histogram":
                    
    setPlotType(PLOTTYPE_HISTOGRAM,2);
                    break;
                case 
    "FlatLines":
                    
    setPlotType(PLOTTYPE_FLATLINES,2);
                    break;
                case 
    "InstantColorLine":
                    
    setPlotType(PLOTTYPE_INSTANTCOLORLINE,2);
                    break;
            }
            
    //Set the Plot Style for the 3rd variable
            
    switch(fpPS3)    {
                case 
    "Solid":
                    
    setDefaultBarStyle(PS_SOLID,2);
                   break;
                case 
    "Dot":
                    
    setDefaultBarStyle(PS_DOT,2);
                    break;
                case 
    "Dash":
                    
    setDefaultBarStyle(PS_DASH,2);
                    break;
                case 
    "DashDot":
                    
    setDefaultBarStyle(PS_DASHDOT,2);
                    break;
                case 
    "DashDotDot":
                    
    setDefaultBarStyle(PS_DASHDOTDOT,2);
                    break;
            }
        
    setDefaultBarThicknessMath.round(fpThick1), ); 
        
    setDefaultBarThicknessMath.round(fpThick2), );
        
    setDefaultBarThicknessMath.round(fpThick3), );
        
    setDefaultBarFgColor(fpColor1,0);
        
    setDefaultBarFgColor(fpColor2,1);
        
    setDefaultBarFgColor(fpColor3,2);
        
    nDYNAMICSUPPRESS KPLib.KPDynamicSR(fpSymbolfpInterval);
        
        
    bInit true;
        }   
    //end of initialization   
        
        //  Plot the correct variables
        
    switch(fpPVar) {
            case 
    "All":
                return new Array(
    nDYNAMICSUPPRESS[0].getValue(0), nDYNAMICSUPPRESS[1].getValue(0), nDYNAMICSUPPRESS[2].getValue(0));
                break;
            case 
    "Support":
                return new Array(
    nullnullnDYNAMICSUPPRESS[2].getValue(0));        
                break;
            case 
    "Resistance":
                return new Array(
    nullnDYNAMICSUPPRESS[1].getValue(0), null);        
                break;
            case 
    "Mean":
                 return new Array(
    nDYNAMICSUPPRESS[0].getValue(0), nullnull);       
                break;
            case 
    "Support/Resistance":
                return new Array(
    nullnDYNAMICSUPPRESS[1].getValue(0), nDYNAMICSUPPRESS[2].getValue(0));            
                break;
        }        

    My feeling is that instead of just getting the value from the array, the entire calculation is being done over for successive calls. So in reality, since the array has 3 elements, the indicator is being calculated 3 times instead of just once

  • #2
    Yep, it is being done three times instead of once. We'll be looking at optimizing these things in the coming versions.

    Comment

    Working...
    X