LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Discrepancy between execution time of state machine and flat code

I am trying to optimize the performance of my application, and I've found that the same code executed as a case in a state machine, and flat on the block diagram takes a dramatically different amount of time to run. I'm trying to figure out what I'm missing here. The picture shows a test vi I threw together (the next post will have the diagram image for the "Add New" case of my Buffer Engine.vi - basically the same as what is in frame 5). The fifth frame in the sequence is what I am concerned about. It shows that executing the case in the state machine takes ~700ms, and flat, ~113ms.

Any thoughts?
Chris
0 Kudos
Message 1 of 5
(2,990 Views)
Here is the Add New case from my Buffer Engine.

Chris
0 Kudos
Message 2 of 5
(2,982 Views)
Okay, so I'm hacking chunks out of my code to find the culprit. Turns out it's the shift register that the 9x300k I32 array is stored in. So I guess the question is now, is 700ms a reasonable amount of time to access a little over 10MB of memory? In Buffer Engine, it is actually being accessed twice, once to read, and again to write the changed array. For kicks, I tried replacing the shift register with a Global variable. In that case it took over 1100ms to do the same thing (read & write).

I'm using the array as an acquisition pre-event buffer. In the case of an event, the entire buffer gets written to disk. Any suggestions on a better way to deal with this? I am going to see if I can duplicate the functionality with a fixed size queue to see if that is faster.

Chris
0 Kudos
Message 3 of 5
(2,963 Views)
The "delete from array" and "insert into array" functions are low performance because they both cause a change in array size and thus cause expensive memory allocation operations.

I cannot really tell the details of your code, but you should try to keep the 2D "data" array in the un-initialized shift register at a constant size. Then you can use e.g. "replace array subset" to merge in your new data. This will be definitely more efficient.
Message 4 of 5
(2,945 Views)
Thanks for the suggestion Altenbach. I had to insert a for loop to replace array subset indivually for each column of new data to place in the buffer, but even with the extra processing, the result was about 80% faster. I guess I'll have to come up with a system to track where to place the data (it was convenient to always drop the data at the end..), but that shouldn't be an issue.

However, this suggestion doesn't address the original concern. The same array resizing was going on in both the subvi and the sequence frame. This improvement should increase the performance of each, but doesn't explain the difference.

As an aside, I contemplated using a queue, but without the ability to dequeue from both the beginning and the end, I don't see how I can use them for this. I want to trash the oldest data, not hold up the acquisition. In any case, I don't think it would be faster because the memory isn't pre-allocated. Now I am considering just storing the data in a control, and passing the reference as necessary. The question is, is reading the value from a control faster than reading from a shift register?

Thanks again.
Chris
0 Kudos
Message 5 of 5
(2,926 Views)