LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need Speedup

Solved!
Go to solution

This runs a bit slow.  Any suggestions on improving performance.  Typically it will iterate between several hundred and a few thousand times.

paul_a_cardinale_1-1712343573285.png

0 Kudos
Message 1 of 21
(2,032 Views)
Solution
Accepted by paul_a_cardinale

This is nearly 10x faster..

 

Original -     0.14s

Metod #2 -  0.01s

 

I would have been satisfied with 0.1s for 10,000 iterations to begin with. 😉

 

20240405_cds.png

Message 2 of 21
(2,012 Views)

Thanks.

Although 0.1s isn't much, that loop goes inside another loop that iterates several hundred times.

Message 3 of 21
(2,003 Views)

I have always found that building a string as you do is slow. Of course that benchmark is meaningless because both version run in parallel, potentially stepping on each other's toes. Also, the SR should probably be initialized.

 

Currently posting by phone, will have a look later.

0 Kudos
Message 4 of 21
(1,992 Views)

@altenbach wrote:

 Also, the SR should probably be initialized.


The SR is the slow part. Remove the SR and concatenate the string like the example above, either by specifying concatenate on the edge of the for loop, or build an array and concatenate after the array, no major difference. Not as fast as the one above, but a significant speed up.

 

 

0 Kudos
Message 5 of 21
(1,980 Views)

Note that you can even parallelize the FOR loop. This one is significantly faster on my laptop (3ms vs 480ms).

 

altenbach_0-1712365120025.png

 

There are also a few other alternatives in the other cases, so play around. I am sure there is some slack left.....

 

I took the liberty to change the Y into a simple ramp, but it really should not make a difference.

 

Message 6 of 21
(1,932 Views)

Can the number be statically sized wrt the number of digits? If so the string could be allocated all in one go and then replace the segments with the correct numbers.

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 7 of 21
(393 Views)

Or even allocate a string all at once for the maximum possible number of digits for all entries and replace into that and trim down at the end. Eliminates all the individual string allocations that need to happen with the loop, whether its the reallocation being done for the SR every time or the individual strings that then get concatenated.

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 8 of 21
(391 Views)

I've seen that many times, Strings in shift registers changing sizes are slow, i assume the memory manager doesn't like it. It's fast to make an array of strings and merge them in the end, as the examples do. Making a preallocated string and replacing content might be a good (and old school) alternative.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 21
(326 Views)

The format into string might also be slow.

 

Format Into String probably parses the format string each iteration. While the string can't change in this example, I don't think the function will change into another function if the format string is a constant.

 

There's a chance though that concatenating a string from constants and more primitive functions is slower that parsing the format string. 

 

This could be benchmarked, but for me refactoring Format Into String usually made things faster...

Message 10 of 21
(299 Views)