LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate the execution time of the while loop in real-time system

Hi everyone. I'm new to labview and I'm developing a real-time system. I try to acquire a series of data of 20 each time and then calculate the core of gravity of the 1D data. Now I need to know the calculating time to test the fastest rate I can go. But I don't know how to calculate the time since both the DAQmx read  and calculating code are both inside the while loop structure but I only want to get the time of the calculation part. Any feedback would be great. Thanks.

 

realtime calculate.png

 

 

0 Kudos
Message 1 of 8
(3,881 Views)

Hi search for Altenbach's presentations on code optimization, there you will find a lot of hints on how to measure execution time...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(3,874 Views)

You cannot calculate it. You actually need to measure it. 😄

0 Kudos
Message 3 of 8
(3,840 Views)

Still, measuring the execution time of the calculation will not give you any reliable indication on "how fast you can go". Do the experiment and simply see how fast you can go, i.e. increase the rate until things fall apart. 😄

 

You might also play with the buffer size. Currently you use buffer size=samples/channel. Why?

 

Also, since your samples/channel does not change during the loop, you could pre-calculate the ramp as follows:

 

 

Gravitas.png

 

 

Still, there are many glaring problems everywhere in your code:

  • Why are you reading the sample clock rate via a value property node???
  • Why are you pre-pending an empty array (several places).
  • Why are you using a complicated insert into array when all you need is a built array in concatenate mode. (top middle)
  • Why are you building all these 2D arrays if you ever only keep the first row???

 

0 Kudos
Message 4 of 8
(3,834 Views)

Now look at your extremely convoluted setup of the arrays. You are creating these gigantic 2D arrays just to throw everything but the first row away a nanosecond later. You are generating up to 40x more data for nothing!

 

All you need is much less for the exactly same result:

 

ArraySetup.png

0 Kudos
Message 5 of 8
(3,821 Views)

Thank you so much. I really appreciate!

0 Kudos
Message 6 of 8
(3,736 Views)

Actually I want to measure the time of calculating. I don't think it has something to do with the reading rate.

0 Kudos
Message 7 of 8
(3,719 Views)

@chen3477 wrote:

Actually I want to measure the time of calculating. I don't think it has something to do with the reading rate.


Our presentation from a few years ago has already been mentioned. Did you even look at it?

 

In my opinion, the calculation time here is probably insignificant and you should be able to do any speed your hardware supports. The calculation is NOT the time limiting step and even if you know the exact calculation time, you won't be able to draw any conclusions about the max data rate. If you are still worried about performance, use a queue and do the calculation in parallel in a separate loop.

0 Kudos
Message 8 of 8
(3,706 Views)