LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Coerce (red-dot) is Faster Than Convert and the new Coerce To Type

Solved!
Go to solution

The following snippet demonstrates that a wired red-dot coerce is several times faster than converting the datatype. That's not too surprising, just because I have heard that this is the case, but I would like to know what the red-dot is doing under the hood that makes it so much faster, yet "incorrect" (sort of).

 

Going further, I wanted to see if the new Coerce To Type would be as fast as a red-dot coerce. Turns out, it is roughly as slow as Convert.

 

Can someone explain or join in on a discussion about this? Am I wasting time and nodes converting?

 

 

coerce faster.png

Richard






0 Kudos
Message 1 of 10
(4,024 Views)

How valid is your test?  Is the compiler smart enough to know that you are converting the same constant many times and reuse the conversion?  What about constant folding?

 

Lynn

0 Kudos
Message 2 of 10
(4,018 Views)

@johnsold wrote:

How valid is your test?


The test is the test. My point is, with THIS vi, Coerce is fast.

 


@johnsold wrote:

What about constant folding?


 

Yep, replacing with controls make Coerce slower Smiley Wink Replacing the constants with changing numbers does also. Only under the shown scenario is Coerce fastest.

 

Richard






0 Kudos
Message 3 of 10
(4,006 Views)

@broken Arrow wrote:

@johnsold wrote:

How valid is your test?


The test is the test. My point is, with THIS vi, Coerce is fast.

 


johnsold is correct, its not valid test for "Coerce vs Convert" challenge. Its a test for "Folding vs Folding" efficiency. First you should avoid constand folding (for example, connect index of for loop insted of constant), then your measurement will be more or less correct. Hint: you can turn on visualisation for constant folding in Tools->Options-Block Diagram.

0 Kudos
Message 4 of 10
(3,980 Views)

It was soooo long ago I don't think I will be able to find the thread or either sure who it was so I'll guess Greg McKaskle, but maybe wrong...

 

The explicit conversiontakes alittle more over-head than the implied coercion. I have not benchmarked it lately but every time I did the implied coercion was faster.

 

Ben

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

Are you really running these loops in parallel?

 

Anyway, I typically don't trust benchmarks with diagram constants and folded loops. They are probably meaningless.

 

About the difference between implicit and explicit coercion, this old thread might shed some light. 🙂

Message 6 of 10
(3,947 Views)

Thanks for the link Altenbach! Very informative.

 

further...

How about if I asked a more specific question regarding my VI:

Given the state of constant folding in these loops, why is coercing so much faster than converting?

Richard






0 Kudos
Message 7 of 10
(3,925 Views)
Solution
Accepted by topic author Broken_Arrow

It is not. Since you have debugging enabled, some extra code is probably generated to prrobe the loops during execution.

 

If you disable debugging, all times are 0 or 1ms. 😄

Message 8 of 10
(3,894 Views)

---duplicate---

0 Kudos
Message 9 of 10
(3,892 Views)

@altenbach wrote:

[...] 

If you disable debugging, all times are 0 or 1ms. 😄


So coercion is twice as fast. Smiley Very Happy

Thanks Altenbach.

Richard






0 Kudos
Message 10 of 10
(3,872 Views)