PL code execution time - strange behavior

Questions about MultiCharts and user contributed studies.
Zheka
Posts: 92
Joined: 13 Jan 2016
Has thanked: 3 times
Been thanked: 14 times

PL code execution time - strange behavior

Postby Zheka » 06 May 2017

I have stumbled upon an interesting phenomenon:

Consider the following piece of code:
-----------------------------------------------------------

Code: Select all

Input:  P(false);

 if P then Value1=Function () ; // where Function is calculationally-intensive

------------------------------------------------------------
Now, even though this line of the code is not supposed to be executed at run-time, the actual time of execution is significantly higher (Optimization time jumps nearly 2x !) in presence of such instruction vs. just simply "commenting out" the line calling a function.

Why would this be??

MultiCharts64 Version 9.1 Release (Build 12587)
Last edited by Zheka on 06 May 2017, edited 2 times in total.

User avatar
TJ
Posts: 6586
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1907 times

Re: PL code execution time - strange behavior

Postby TJ » 06 May 2017

See post #1 and #2
viewtopic.php?t=11713

User avatar
ABC
Posts: 527
Joined: 16 Dec 2006
Has thanked: 111 times
Been thanked: 296 times
Contact:

Re: PL code execution time - strange behavior

Postby ABC » 06 May 2017

Zheka,

I have noticed something similar and it appeared that MC was executing the function, although it shouldn't have. You could add print statements to the function to check if it gets executed.

Regards,

ABC

Zheka
Posts: 92
Joined: 13 Jan 2016
Has thanked: 3 times
Been thanked: 14 times

Re: PL code execution time - strange behavior

Postby Zheka » 06 May 2017

I have just checked it with a print statement: the function does NOT get executed.

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: PL code execution time - strange behavior

Postby JoshM » 13 May 2017

Zheka wrote:Now, even though this line of the code is not supposed to be executed at run-time, the actual time of execution is significantly higher (Optimization time jumps nearly 2x !) in presence of such instruction vs. just simply "commenting out" the line calling a function.


Zheka wrote:I have just checked it with a print statement: the function does NOT get executed.


If you comment out the function call, then that function's code is not included in the DLL that's compiled from the PowerLanguage code. I suppose that if you go to the folder in which those DLLs are stored, the DLL file size differs whether that function is included or not (by commenting it out or not). (That folder is named 'Dlls' and is located in 'C:\ProgramData\TS Support\MultiCharts64\StudyServer\Studies\Dlls' for MultiCharts 64-bit).

What complication mode do you use for your script; 'fast execution' or 'fast compilation'? For 'fast execution' the DLL compiled from the PowerLanguage code should (in theory) be as small and slim as possible. For 'fast compilation' the DLL will contain additional information/overhead more suited for debugging purposes (and should, in theory, give slightly less good performance when the script runs). (This is based on my understanding; not a fact of how MultiCharts operates).

I agree with you Zheka that the script's execution time shouldn't differ when that function isn't called. But if the 'fast compilation' mode is used, I'm a bit more understanding of the speed difference.

Zheka
Posts: 92
Joined: 13 Jan 2016
Has thanked: 3 times
Been thanked: 14 times

Re: PL code execution time - strange behavior

Postby Zheka » 15 May 2017

I am compiling with the default "Fast execution" mode.

@MC: would appreciate your any feedback on the matter.

User avatar
Angelina MultiСharts
Posts: 260
Joined: 28 Dec 2016
Has thanked: 28 times
Been thanked: 66 times

Re: PL code execution time - strange behavior

Postby Angelina MultiСharts » 15 May 2017

Hello Zheka,

Is it a Simple or a Series function?

Zheka
Posts: 92
Joined: 13 Jan 2016
Has thanked: 3 times
Been thanked: 14 times

Re: PL code execution time - strange behavior

Postby Zheka » 15 May 2017

The function is a Simple function , but takes several numericref inputs.

User avatar
Angelina MultiСharts
Posts: 260
Joined: 28 Dec 2016
Has thanked: 28 times
Been thanked: 66 times

Re: PL code execution time - strange behavior

Postby Angelina MultiСharts » 16 May 2017

This behavior is typical for Series functions, or for the functions that contain Series functions.
If it's not the case, please provide the script so we could investigate it.

Zheka
Posts: 92
Joined: 13 Jan 2016
Has thanked: 3 times
Been thanked: 14 times

Re: PL code execution time - strange behavior

Postby Zheka » 27 Oct 2017

Dear MC,

I finally did some investigation re the matter, running the code below over 300 days of 1-min bars:

Code: Select all

// Signal
input: P(false),len(200);
vars: ii(0),strt(0),ed(0),MA(0),sum(0);
Array: Tr[] (0);
 
 once strt=computerdatetime; 
 //once array_setmaxindex(Tr,len) ; 
 MA=waverage(close,5);   
                                                     
 //if P then sum=0;                           
  if P then PL_compiler_functionTestF({Ma,}len);   

 if lastbaronchart then begin
  ed=computerdatetime;
  Print(SecondsFromDateTime(ed-strt),Spaces(2),MillisecondsFromDateTime(ed-strt));
end;

Code: Select all

// Function
inputs: {prc(numericseries),}len(numericsimple);//Tr[maxsize](NumericArrayRef);
vars: ii(0),sum(0);
vars: var0( 0 ), var1( 0 ), var2( 0 ), var3( 0 ) ;
sum=0;

for ii=1 to len begin
  //Tr[ii]=sum;
 //Value1 = LinearReg( c, Len, 0, var0, var1, var2, var3 ) ;
sum=sum+var0; 
end; 
PL_compiler_functionTestF=sum;

Benchmarking to "If P then Sum=0", I found that:

1. "If P then Function ()" - instruction is progressively slower then benchmark from:
- function does not have Series input and does NOT use a Series function (inconsistently slower by 15-17ms)
to
- function does have a Series input and DOES use a Series function (consistently slower by 30+ms)

2. A SINGLE call to "array_setmaxindex() " takes 30ms (??!!!!).

(Latest MCx64 R3, i-6700K, WinServer 2012R2).

Please comment on the above.

Even if you said that "such behavior is typical for functions that contain Series" , I fail to comprehend WHY WOULD THIS BE THE CASE?
If a statement evaluates to False, why would anything after it matter at all?

User avatar
Henry MultiСharts
Posts: 8511
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2733 times

Re: PL code execution time - strange behavior

Postby Henry MultiСharts » 07 Nov 2017

Hello Zheka,

Windows is not a realtime system, executing each task takes some time which depends on the overall system load.
array_setmaxindex() resizes a declared dynamic array to a specified number of elements. It takes some time to allocate memory for these elements, but the amount is insignificant, taking into account that the complete data interval is being benchmarked.
The provided test results should not be considered an issue, as the complete calculation on the entire series is evaluated and not just a single step, the overall performance is not significantly affected.

Zheka
Posts: 92
Joined: 13 Jan 2016
Has thanked: 3 times
Been thanked: 14 times

Re: PL code execution time - strange behavior

Postby Zheka » 07 Nov 2017

Henry,

Sorry, but

1. Why would "if false then Function()" execute slower then "if false then a=b"?
With time of execution dependent on specifics of Function()?

2. Array_setmaxindex () had not been benchmarked over the "complete data interval".
It had been called ONCE. One instruction called once taking 30ms.

Needless to say, I benchmarked under underloaded system and timings were quite consistent.


Return to “MultiCharts”