LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FOR cycle slower than SEQUENCE

Hi everybody,
 
I write a time-critical code, so I experimented something which looks strange to me.
I write a full ATAPI interface, everything works properly, but the speed in my application is critical.
So I have to write 7 registers via an external dll. When I do it in a FOR loop of 7 cycles, the time of writing - so the dll run is included - is 38 us (microsec.)
When I do the same with a SEQUENCE structure, each frame of the 7 are done in 7 us (this is 5-6 times faster than the FOR loop !!!)
 
It is much easier to do this job in a FOR loop, but why is this huge difference in timing? Does it depend on the LV compiler?
 
regards
Gyula
0 Kudos
Message 1 of 17
(3,590 Views)
I just read your post and noticed, that you write "each frame of the 7 are done in 7us". Do you mean all seven sequence frame are executed in 7us or does it take 7us for one frame? This would result in 49us.
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 2 of 17
(3,588 Views)
Hola becktho,
 
Yes, you understood it correct. Is it a known "bug" of LV 7, and woked out in LV 8?
I already have LV8, but all of my softwares are written in LV7, and I want to use them in the future. How can I convert them into LV 8?
 
regards
0 Kudos
Message 3 of 17
(3,575 Views)

Hm - I did not understand it. Does the whole sequence take 7 or 49us?

By the way - if you want to use a vi in LV8.0, just open it. If you have build-scripts, you have to convert them. There is a menu item "convert build script" in the tools menu.

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 4 of 17
(3,572 Views)

Hi

The whole sequence takes 47us. One frame takes 7us. But only when I use the SEQUENCE. With FOR loop it is much slower. However the core of the frames of the SEQUENCE and the FOR loop are the same.

regards

0 Kudos
Message 5 of 17
(3,566 Views)
Well - I don't know how the runtime interprets a for and a while loop, but I could imagine that a jump operation and a comparison (a for loop is basically a jump and a comparison) take more time than the sequence, because this could basically just be ignored. The rte just has to secure that the content of the frames is executed sequentially.
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 6 of 17
(3,564 Views)
Post your code (or a picture of the piece in question) and we can give a better answer.

There could be something else leading to the large difference in timing.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 7 of 17
(3,550 Views)
I agree at least a picture of the two code alternatives would give us a much better idea what you are trying to do..
 
How do you measure the timing in the two cases?
0 Kudos
Message 8 of 17
(3,536 Views)
The attached experimental vi in LV 7.1 shows For Loop vs Sequence Structure.  When run, the difference in timing ranges from 4 mS to 12 mS.  Not much at all.  That is less than 1 mS per loop on the average.  If you remove the random number addition part of the code, the difference in timing ranges from 0 to 2mS.  This suggests that the complexity of the code has something to do with the difference in run times between a for loop and a sequence structure.  I would have never suspected this.  You could try putting in more code into the loop to see what results.  I'm too busy at the moment to take this any further.  However I am interested in the results.
- tbob

Inventor of the WORM Global
Message 9 of 17
(3,521 Views)

The seq running faster than the For loop makes a lot of sense to me.

The seq structure tells the compile how to order operations but has not functionality in itself.

The For loop on the other hand does have code associated with the loop to at the very least, decide if should continue.

Ben

BTW: A While Loop is even slower than a For Loop.

Message Edited by Ben on 08-18-2006 11:48 AM

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 17
(3,519 Views)