LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

execution time slows down the longer the run time

I have developed a save wave program using a ni-scope.  I am trying to save waves as fast as possible into txt files.  When the program first starts running execution time is about 18ms, but after a hour or two it slows down to around 55ms. Is there anyway to speed this process up and keep it at a constant time.  The faster the better.
Mark Mutton
Electrical Engineer
0 Kudos
Message 1 of 5
(3,013 Views)
I believe the problem is that you have a waveform graph in the while loop. a waveform graph will remember all of the data put into it and in your case that is a lot of data
0 Kudos
Message 2 of 5
(3,004 Views)
A couple things you could try.

First, you probably don't want to be opening, configuring and closing the scope on every iteration of the loop. There's no reason to do it. Move the "Open Scope", "Trigger Setup", "Range Setup", "Sample Rate" and "Start" outside the loop to the left and wire the scope refernce to the Scope AcquireI inside the loop and move the "Close Scope" outside the loop to the right so it will close when you hit your Stop button. This could be causing some memory problems as it's constantly allocating and de-allocating resources for the Scope refernce. Make sure you move these outside the While loop and not just outside the Case structure. Remember, they only need to run once.

The only other thing that could be slowing this down is the file writting itself. In general, file I/O is a very slow process. It looks like every iteration you are writting a new file, so finding the end of the file to write to shouldn't be a problem. You could try moving your file writing to a separate loop and send the data to written through a Queue. Look in the Example Finder for some good examples af passing data through a Queue.

Let us know if that helps or not.

Ed


Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Message 3 of 5
(2,992 Views)

(Vivi: Waveform graphs don't remember anything. Maybe you were thinking of charts?)

Mark (eenui): Ed already gave you some great tips for the scope code.

SImilarly, if speed is an issue you should write everything to one single  file, simply appending the current data, preferably in binary form. Use low level file I/O, opening the file outside the loop, and keeping it open during loop execution, just appending data using low level writes. At the end, you close the file on the right, outside the loop.

It is simply NOT a good idea to to create a new file every 20 ms for hours! (This is ~3000 files per minute!!!) I am sure some of the slowdown is from OS overhead due to the sheer number of files, especially if you have an explorer window open for that folder. You'll probably also run into fragmentation issues.

If you want seperate files later (why???), you can process it offline.

It is generally a bad idea to "run as fast as possible", because you loose all reproducibility. Suddenly, execution depends on the speed of the computer, other processes and radom events. What if the computer suddenly starts a weekly virus scan, checks for OS updates, etc.. Everything will behave different on a different computer.

If you don't pace your loop at a fixed speed, all data will be quite useless, because the time of each record cannot be known. You would probably need to also save a timestamp with it.

On an similar note: Your code seems to have some odd flaws. For example, your boolean control for the case structure probably belongs inside the while loop, else it would never get read during the run and would be quite useless. If you only need the control outside the loop, the entire loop would go inside the case structure.

Message 4 of 5
(2,985 Views)
Thank you guys very much. All of this advice is good. I will report back with my results.
Mark Mutton
Electrical Engineer
0 Kudos
Message 5 of 5
(2,949 Views)