03-09-2018 11:11 AM
I am trying to improve the efficiency of my vi as much as possible and was wondering if anyone has any tips, tricks, or corrections. The vi is a temperature monitor that will be built into an exe application. The front panel has numeric indicator for temperature and a waveform chart that will record temperature over the course of a week so it need to be memory efficient. There are also other programs on the computer that will be running alongside this vi so Im also trying to make it the least CPU intensive as I can.
My vi reads the voltage drop across a thermistor using a Labjack( this part of the code will replaced soon with Daqmx when my ni daq comes in the mail). Voltage data is collected at 5 samples/second and the average of those samples is fed into an event structure that times out every second. The event structure calculates the temperature from the voltage and displays the reading on the front panel and also adds it to a waveform chart. I have designed it so the temperature indicator is updated every second while the waveform chart will update less frequently to save memory. In the final build the waveform chart will update every 1 minute, 5 minutes or 10 minutes. depends how efficient I need it.
I used a Case Structure inside the event case to control when the waveform chart updates the while loop iteration is divided by a number to be determined and if the remainder is 0 the chart updates. Is there a way to do this operation so that the case structure inst continuously polling?
shown in the second image is the sequence structure containing the while loop. The first sequence when it starts up is it reads default values from a text file and writes them to local variables. The last sequence writes the local variables to the same file.
Any help is appreciated, Thanks!
03-09-2018 11:29 AM - edited 03-12-2018 11:07 AM
How wide is your screen exactly??? 😮
Just glanced at it for 20 seconds, but here are some observations:
03-12-2018 05:38 AM
@el_ManBearPig wrote:
I am trying to improve the efficiency of my vi as much as possible
Is that really necessary? It's obviously a lot of fun trying to tune code until it's optimal.
You're doing tiny calculations on scalars. Is it even noticeable?
03-12-2018 11:06 AM
wiebe@CARYA wrote:
@el_ManBearPig wrote:
I am trying to improve the efficiency of my vi as much as possible
Is that really necessary?
There is run time efficiency, but there is also coding style to make editing, debugging, adding features, avoiding mistakes, etc. more efficient.
Making the code run more efficiently, you might save a few nanoseconds. Making the code design more efficient, it might save you weeks in the future 😄
03-12-2018 11:31 AM
Thanks for the reply,
I use the event structure because my understanding is that the functions inside it are inactive until the timeout every second instead of polling multiple times a second. This way the case structure inside is only polled once a second instead of 5 or 10 times a second. Is it better to have two case structures polling all the time?
03-13-2018 04:17 AM
@altenbach wrote:
wiebe@CARYA wrote:
@el_ManBearPig wrote:
I am trying to improve the efficiency of my vi as much as possible
Is that really necessary?
There is run time efficiency, but there is also coding style to make editing, debugging, adding features, avoiding mistakes, etc. more efficient.
Making the code run more efficiently, you might save a few nanoseconds. Making the code design more efficient, it might save you weeks in the future 😄
Well, obviously. OP is only talking about CPU performance and I don't thing that should be a priority here.
Memory efficiency would be another factor.
In this piece of code, cleaning up \ coding style could be improved on. There's not that much going on, and the code is not terrible. But before scaling up the application, I'd think about modularity. This (the beginning) is the time to do that.