LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best Practice: Using Constants with Loops

 


@smercurio_fc wrote:

I like to use a numeric control set to have a default value to the value that I want and then I use a local variable to get the value.


No, not a control!!! Use a hidden numeric indicator instead. 😄

 

0 Kudos
Message 11 of 14
(2,459 Views)

 


@altenbach wrote:

 


@smercurio_fc wrote:

I like to use a numeric control set to have a default value to the value that I want and then I use a local variable to get the value.


No, not a control!!! Use a hidden numeric indicator instead. 😄

 


I'd recommend a hidden string control and then using String to value! That way it's general and can always be used!

/Y

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 12 of 14
(2,444 Views)

A couple years ago, I began an "uphill struggle" where I began to become more and more anal retentive about nitpicky details like this one. In some instances, this question is very important! For instance, a very large (bytes) constant inside of a Loop running millions of times. Here, performance is a big issue!

 

On the other hand, a numeric scalar constant inside a loop running a couple dozen times is of negligible performance hit. Still, I would meticulously try to squeeze the absolute best performance out of every system, many times at the expense of a good-looking diagram.

 

More recently, I have placed a higher importance on syntactical beauty, yes, even at the expense of a few clock cycles. A good-looking diagram translates to saved time when troubleshooting or revisiting old code. Colleagues will love you. I mean, who wants a spaghetti VI with 19.9994% CPU utilization rather than one that looks good at 20%?

 

Part of "syntax beauty" also includes consistency. If there are two methods that perform slightly better in different situations (for instance, the "Vestigial For Loop" around an otherwise polymorphic primitive), sometimes it's better just to be consistent than to gain a few clock cycles.

 

So, bottom line: I always choose what looks best when we're talking about microseconds of execution, but every now and then the obligatory performance benchmark will dictate best practices. The answer to this question is academic, and only becomes practical when there's appreciable performance gain.

0 Kudos
Message 13 of 14
(2,431 Views)

By the way, good question! My favorite posts are about "best practices", and especially when you get a little humour splashed in!

0 Kudos
Message 14 of 14
(2,430 Views)