LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Faster: Sequence Local or Global Variable?

I have a While loop that runs more-or-less forever, and contained within it
is a Sequence which runs on every iteration. I have a question about the
CPU overhead involved in the loop which I will illustrate with an example.

Say there are 4 frames in the Sequence. In frame 1, I write a value to a
global. In frame 3, I want to use the value from that global. In terms of
CPU cost, is it more efficient (i.e. quicker) to actually READ from the
global in frame 3, or to wire a Sequence Local going forward from frame 1?
There are no race conditions or other dependencies to worry about in this
case, just wondering about the overhead.

Thanks!

Justin Goeres
Project Engineer
Indio Systems, Inc.
Pleasanton, CA
0 Kudos
Message 1 of 5
(2,743 Views)
Another note to my original post:

Now suppose I have the same situation I just mentioned, but I've got 30
variables. Better/faster to use globals, or Sequence Locals in that case?
i.e. Is one method always faster, or are there other issues that arise when
the "density" of the variables is greater?

Thanks!
0 Kudos
Message 2 of 5
(2,743 Views)
Justin Goeres wrote:

> I have a While loop that runs more-or-less forever, and contained within it
> is a Sequence which runs on every iteration. I have a question about the
> CPU overhead involved in the loop which I will illustrate with an example.
>
> Say there are 4 frames in the Sequence. In frame 1, I write a value to a
> global. In frame 3, I want to use the value from that global. In terms of
> CPU cost, is it more efficient (i.e. quicker) to actually READ from the
> global in frame 3, or to wire a Sequence Local going forward from frame 1?
> There are no race conditions or other dependencies to worry about in this
> case, just wondering about the overhead.
>
> Thanks!
>
> Justin Goeres
> Project Engineer
> Indio Systems, Inc.
> Pleasanton, CA

Justi
n,
I would encourage you to read ch 28 of the G Programming Reference Manual.
This describes some of the issues that you are asking about.

I would also suggest that you not use sequences, you can get the same
fucntionality
using data flow and SubVIs and your code will be much easier to read and
maintain.

I would not use globals if I could find another way to do the job. A global
will
make a copy of itself increasing mem usage and CPU time. They are also
difficult to
use if you have race conditions.

A sequence local is even less desirable. They are hard to follow and if you
have
very many they obscure the intent of the design beyond recognition. I once had
to
debug some code that had 15-20 sequence locals of different types. After a
couple
of days I gave up and redesigned the whole thing in less than a day.

Kevin Kent
0 Kudos
Message 3 of 5
(2,743 Views)
Kevin,

How do you eliminate the use of sequence locals if you are using a
sequence, local variables? Or is your meaning that you eliminated the sequence
all together?

Henry
0 Kudos
Message 4 of 5
(2,743 Views)
Henry Coulter wrote:

> Kevin,
>
> How do you eliminate the use of sequence locals if you are using a
> sequence, local variables? Or is your meaning that you eliminated the sequence
> all together?
>
> Henry

Henry,
I meant to eliminate sequences all togehter. You are correct in the reasoning
that the
only options to a sequence local is a pure local (very bad) or a global (almost
as bad).

I realize that the sequence is there to be used and MAY have some value.
BUT if you are passing data around there is no reason to use them
since the data flow will control the sequence.

The ONLY time I use a sequence is when I use one with a SINGLE frame
and put something inside the frame. This is usually a "Wait" function that does
not have any inputs (other than the
time which is a constant) that I can use
to force dataflow sequencing.

I have no intention of telling anyone how to code their VIs, that is a personal
choice
and a matter of one's programming style. I have used LabVIEW since version 3.x
and
I have always tried to get the smallest, fastest, easiest to read code that
I can, this for
me means No Sequences.

Hope this was helpful.
Kevin Kent
0 Kudos
Message 5 of 5
(2,743 Views)