LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace Flat Sequence Structure?

Solved!
Go to solution

I have been reading a bit in the forum and a lot of people recommended not to use sequence structures. Here is the situation: I have a tick count at the beginning for the iteration (and another at the end). I would like to force them to count before (and after) anything else. The code that I am working on let all data passing through flat sequences structures which contain tick counts only. Is there any different way that you can do it without the sequence structures?

 

Thans

0 Kudos
Message 1 of 8
(5,223 Views)

Use OpenG

 

They have timing VI's that encapsulate Wait, Tick Count insied an error-case.

 

But also note that flat sequences are considered 'correct' when using tick count or wait  (it's the exception where sequences are ok). So don't rewrite all your existing code, use the OpenG vi's for the newer code.

 

Felix

Message 2 of 8
(5,211 Views)
Solution
Accepted by topic author crazycompgeek

The recommendation not to use sequence structures applies to most of the cases where people use them.  State machines are the preferred (and best) method.  However, that does not mean that there is never a good use for a sequence structure.  In your case, when you want to time something, it is perfectly acceptable.  An example is shown in the first snippet below.

 

 

There is an alternative however.  You can use a timed loop to time your code.  Someone here once posted an example.  I forgot who it was and which thread it was in.  It went something like the second snippet.

 

I would like to know why there is a difference in speed between these two methods:

 

 

Timing.png

- tbob

Inventor of the WORM Global
Message 3 of 8
(5,207 Views)

tbob wrote:

[...]  You can use a timed loop to time your code.  Someone here once posted an example.  I forgot who it was and which thread it was in.  [...]


http://forums.ni.com/ni/board/message?board.id=170&message.id=501103&query.id=5008538#M501103

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 4 of 8
(5,190 Views)

Tbob, I would guess the speed differnece is due to the wireing of the array. In the timed sequence, it is going 'nowhere', so the compiler might skip a buffer allocation.

 

Felix

0 Kudos
Message 5 of 8
(5,167 Views)

tbob wrote: 

I would like to know why there is a difference in speed between these two methods:

 

 

Timing.png


 

First of all, this benchmark is quite meaningless. What are you trying to measure?
 
  • Since there is no defined execution order both structures run in parallel, and whatever can grab more CPU cycles will be faster.
  • Avoid diagram constants to prevent constant folding.
  • Disable debugging.
  • If you want to force use of a certain CPU, try 0 instead of 1. Not everybody has multiple cores. 😉
0 Kudos
Message 6 of 8
(5,149 Views)
Thanks everyone. It seems like the timed loop is something I need. If not, I probably go with the ss.
0 Kudos
Message 7 of 8
(5,069 Views)

altenbach wrote:

 

First of all, this benchmark is quite meaningless. What are you trying to measure?
  • Since there is no defined execution order both structures run in parallel, and whatever can grab more CPU cycles will be faster.
  • Avoid diagram constants to prevent constant folding.
  • Disable debugging.
  • If you want to force use of a certain CPU, try 0 instead of 1. Not everybody has multiple cores. 😉

I was not trying to benchmark anything.  I just noticed the difference in execution speed and wanted to know why there was a difference.  The two snippets are not in the same vi,  they are separate.  Sorry I didn't explain that.  I'm not using these anywhere, they were just an example to show 2 methods for timing.

Perhaps Felix is right.  The output array in one vi but not the other could make a difference in execution speed.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 8
(5,044 Views)