01-18-2022 10:28 PM
Hi All.
I have a sample of LV below with initialisation of variables both inside and outside of a while loop.
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.....
01-19-2022 03:23 AM
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).
01-19-2022 04:05 AM
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
01-19-2022 05:06 PM
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?
01-19-2022 07:51 PM
@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.
01-20-2022 04:06 AM
@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