Page 1 of 1

PL code execution time - strange behavior

Posted: May 06 2017
by Zheka
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)

Re: PL code execution time - strange behavior

Posted: May 06 2017
by TJ
See post #1 and #2
viewtopic.php?t=11713

Re: PL code execution time - strange behavior

Posted: May 06 2017
by ABC
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

Re: PL code execution time - strange behavior

Posted: May 06 2017
by Zheka
I have just checked it with a print statement: the function does NOT get executed.

Re: PL code execution time - strange behavior

Posted: May 13 2017
by JoshM
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.
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.

Re: PL code execution time - strange behavior

Posted: May 15 2017
by Zheka
I am compiling with the default "Fast execution" mode.

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

Re: PL code execution time - strange behavior

Posted: May 15 2017
by Angelina MultiСharts
Hello Zheka,

Is it a Simple or a Series function?

Re: PL code execution time - strange behavior

Posted: May 15 2017
by Zheka
The function is a Simple function , but takes several numericref inputs.

Re: PL code execution time - strange behavior

Posted: May 16 2017
by Angelina MultiСharts
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.

Re: PL code execution time - strange behavior

Posted: Oct 27 2017
by Zheka
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?

Re: PL code execution time - strange behavior

Posted: Nov 07 2017
by Henry MultiСharts
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.

Re: PL code execution time - strange behavior

Posted: Nov 07 2017
by Zheka
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.

Re: PL code execution time - strange behavior

Posted: Feb 10 2021
by janus
Zheka, have you solved this issue? MC do you have an answer for this strange behavior?