LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LV compiler discussion - optimisation - minor point

Hi All.

I have a sample of LV below with initialisation of variables both inside and outside of a while loop.

 

pushkin_0-1642565781900.png

Is the approach of doing this outside the while loop any better ??

 

The are both static in nature.  The compiler could just as well establish both inside and outside variables prior to execution.

 

I need to whole vi (under development) to be quick in execution for all possible commands.

 

Regards JC.....

0 Kudos
Message 1 of 6
(1,117 Views)

Initializing inside the loop allow you to start over with another session without terminating the program.

It may be necessary if the initialization depends on variable parameters (for example the maximum number of samples to be acquired).

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 6
(1,089 Views)

I don't think I've ever even thought about initialising outside an FGV/Action engine. The BD gets too big to view and easily maintain as the case structures grow, and well defined cases will always execute fast.
When you initialise the whole module within the program can be more key to overall fast execution sometimes.
James

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 3 of 6
(1,083 Views)

Thanks for the comments.

I would expect a execution speed improvement with the outside of loop version.

This would be the case if the inside loop version computed the "new" static array on each execution.  There may or may not be some computation with the inside version.  I do not know how clever the compiler is.  Maybe others do?

0 Kudos
Message 4 of 6
(1,048 Views)

@pushkin wrote:

Thanks for the comments.

I would expect a execution speed improvement with the outside of loop version.

This would be the case if the inside loop version computed the "new" static array on each execution.  There may or may not be some computation with the inside version.  I do not know how clever the compiler is.  Maybe others do?


There's a fair chance that the compiler compiles it into identical code.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 6
(1,035 Views)

@billko wrote:

@pushkin wrote:

Thanks for the comments.

I would expect a execution speed improvement with the outside of loop version.

This would be the case if the inside loop version computed the "new" static array on each execution.  There may or may not be some computation with the inside version.  I do not know how clever the compiler is.  Maybe others do?


There's a fair chance that the compiler compiles it into identical code.


(As Bill knows, that would depend on if the VI is called asynchronously or not and whether or not the first called case of the VI is deterministic. If it is deterministic, then compiler can definitely compile into identical code.) .
only you know the answer in your case pushkin.

James

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 6 of 6
(1,007 Views)