LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

performance vs cleanliness

Hi, I have always wondered for what should I go for, performance or cleanliness? Because most of the time in big projects you get stuck with this. An example could be using passing a cluster or array by reference (New Data Value Reference), and pass the wire through many loops, or just using a local variable to read the cluster/array in each loop? This is just one example just to get the idea, because there are many more examples of questions like this.

 

Thanks!

0 Kudos
Message 1 of 9
(3,942 Views)

I often find that the performance updates I make cause more cleanliness.  But in general, I go for the performance.  But I'm also very OCD, so I still end up with a mostly clean diagram.

 

In your example, do not use the local.  Those will just cause more problems.  What you actually may want is an Action Engine.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 9
(3,938 Views)

Generally, cleanliness is preferred unless permance is a critical necessity for the system to function. At least thats what I've heard.

0 Kudos
Message 3 of 9
(3,936 Views)

For your specific example, be aware that reading a LOCAL variable creates a COPY of the data.  Every time.

 

That makes a difference in performance if the array size is large.

 

In general, go for performance, and cleanliness can follow.

 

It's a whole lot easier to clean up a well-performing code, than to speed up a clean, but ill-performing code.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 4 of 9
(3,929 Views)

"...Premature optimization is the root of all evil..."

 

(c) Donald Knuth, 1974


Message 5 of 9
(3,921 Views)

@Andrey Dmitriev wrote:

"...Premature optimization is the root of all evil..."

 

(c) Donald Knuth, 1974



 

"God grant my the peace to acept the the non-optimized performance, knowlege to let me optimize and the wisdom to know when to optimize." (paraphrase of teh prayer of St Fancis)

 

WIth time and experience we learn when we have to optimize and we do not have to optimize.

 

When I develop my designs I am continually asking myself (how much data will be in this wire, how often, and what the end effect seen by the customer would be.

 

If you don't have that "feel" yet, start writing benchmarks to test your code any time you see a "big wire". After running benchmarks, playing "wack-a-dot", and learning how to optimize, you will remember what needs to be checked and what does not.

 

The other thing you can do is to keep the "Windows Task manager" open when you test your code. When you notice your code is killing the CPU, stop and figure what you just did, then don't do that again.

 

I am still learning and will continue to do so.

 

Have fun,

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 9
(3,911 Views)

I prefer my code to be readable and not much care about the cleanliness. As you make your code readable that is suffiecient for the other developers because you are not going give the code to your customer but your front panel should be very good and easly understandable (tip strip). Rest -dtto Ben's post. Also don't forget to read this ( Ben you know this very well 🙂 )

-----

The best solution is the one you find it by yourself
0 Kudos
Message 7 of 9
(3,890 Views)

I always aim for clear, concise and readable code first and foremost. If you write spaghetti code it generally doesn't matter how fast it is because in the end you can't effectively maintain it. Focus more on good coding styles, modularization, frameworks and best coding practices. When necessary optimize. Unreadable codes quickly becomes more troublesome as it ages. Good clean code is easier to maintain and enhance.

 

It should be noted that good designs will often lead to pretty good performance anyway. As you modularize your code you tend to minimize the need for passing tons of data around. The data stays with the code that needs it. If you need to run wires through code just to reach subVIs then you probably don't have a very good design in the first place.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 8 of 9
(3,877 Views)

Thanks to all for the answers!

I use many Action Engines, I am still at college but I want to upload some of my programs for feedback.

So since the beginning I'll do my best to try to code clean, and like most of everyone said: Keeping it optimized will get the code clean 🙂

 

Thanks again!

0 Kudos
Message 9 of 9
(3,835 Views)