LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Efficient use of case structure

I frequently need to trap a variable equal to zero or another number (-1). I have frequently connected the variable to the select input of a case structure set one state to the number I wish to trap using the default case for the normal code. I this more efficient less efficient or no difference to using an "equals zero vi then a Boolean to control a simple true/ false case structure?

0 Kudos
Message 1 of 6
(3,226 Views)

I don't know.  You could write some test code that does each one repeatedly in a loop and see which takes longer.

 

But why are you concerned?

0 Kudos
Message 2 of 6
(3,221 Views)

To add the following:

What are possible future changes to the code? To be more specific: Does comparing the numeric value to a boolean state (equal, not equal, ...) restrict future changes?

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 6
(3,214 Views)

It depends on what is in the case structure. If it is a simple selection then the following snippet is faster, if you have subVIs in your case structure, then you will need a case structure. Note that the Slect function is faster than the case structure, but both a pretty fast. Only if you have a tight loop with millions of points will you start to see the difference.

 

Cheers,

mcduff

 

Select.png

0 Kudos
Message 4 of 6
(3,190 Views)

In cases where all I care about is if something's true or not - for instance, a string match offset being -1 or not - I test for "T/F" instead of "-1 or other number" so I can use "select" instead of a case structure (provided it's something simple like choosing one value or another).

 

[edit]

 

oops, like mcduff

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
(3,187 Views)

In this case the select toll is not appropriate as a decision is made whether or not to run some test software based on the value returned for a data and result index a value of -1, this case, means no data or index so don't run the test

0 Kudos
Message 6 of 6
(3,136 Views)