LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SLOW FUNCTION - String subset

Solved!
Go to solution

Hello Everybody,

 

in the attacched picture, I have a for-loop that goes through a 1D-array of strings, looks for elements starting with "02", and returns their index withing the array.

 

The problem is that is very slow, it takes about 18 seconds to scan the entire file array which is about 20000 elements long. Since I am using a PC, I was hoping to do the job in a few seconds.

 

Any suggestions?

 

Thanks in advance,

 

Lorenzo

0 Kudos
Message 1 of 12
(4,651 Views)

I would guess, the running display of variables is the cause for the bad performance.

Use modulo with the loop index to make them update only after each Nth run of the loop.

 

0 Kudos
Message 2 of 12
(4,616 Views)
Solution
Accepted by loba

Ok, here are some things I noticed that might be slowing things down:

 

- Property nodes inside the loop will definitely slow down your loop. It's also dead code - you only need to update the scale maximum once before the loop runs.

- Local variables are also (i think only marginally) slower than using the terminal. LabVIEW is a data flow language - you should use wires to connect things together!

- Using the conditional indexing will cause dynamic memory allocations as it has to resize the array...you could improve this by preallocating an array to the number of iterations of the for loop and then resize the array at the end


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 3 of 12
(4,599 Views)

@Sam_Sharp wrote:

Ok, here are some things I noticed that might be slowing things down:

 

- Property nodes inside the loop will definitely slow down your loop. It's also dead code - you only need to update the scale maximum once before the loop runs.

- Local variables are also (i think only marginally) slower than using the terminal. LabVIEW is a data flow language - you should use wires to connect things together!

- Using the conditional indexing will cause dynamic memory allocations as it has to resize the array...you could improve this by preallocating an array to the number of iterations of the for loop and then resize the array at the end


You're right on the first 2 points, i think #3 is wrong though. If memory serves there was a thread with tests which suggested that construction uses preallocation and array trim.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 12
(4,590 Views)

Ah, maybe they changed it, but when it was first available I thought it did exactly the same as a shift register + build array implementation.

 

Although having done a quick google search, it seems as though I was mistaken - http://digital.ni.com/public.nsf/allkb/CDD9EC4C82E7170286257A22006E9112


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 5 of 12
(4,577 Views)

@Yamaeda wrote:

 

You're right on the first 2 points, i think #3 is wrong though. If memory serves there was a thread with tests which suggested that construction uses preallocation and array trim.

/Y


It might in recent LabVIEW versions but it didn't initially when the feature appeared.

 

As to various things slowing down the executation I could name a few, some more serious than others and some having been mentioned:

 

1) use of a property node inside the loop, -> very bad and totally unneccessary here as you update always with the same value;

2) array indexing inside the loop with loop iteration counter instead of autoindexing on the loop boundary, not likely a big issue but stll less than ideal

3) String subset is definitely an issue although LabVIEW might be smart enough to use subarrays in these cases, I would use Match Pattern instead, which is faster than the PCRE function and more than enough in this case as it doesn't need the PCRE features, which nobidy except some PCRE gurus can remember.

4) Update of the substring requires a lot of processing power to render the strings, remove after having debugged the function

 

String Array Search.png

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 6 of 12
(4,566 Views)

I might be quite wrong about the conditional array. However, it's not the culprit here. The property node and string update is rather costly. Also, as we dont see the full diagram, is OP rereading the file and/or reading in an inefficient manner?

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 12
(4,556 Views)

The obvious problems are the property node (as others have noted) and the copy of a very large array of strings that is done on each read of the "Imported Hex File" local variable.  String subset and everything else should be blindingly fast.   Remove the property node and variable to outside the loop.

0 Kudos
Message 8 of 12
(4,553 Views)

ConditionalStringArray.png

Just a small tweak to what OP posted should make it noticably faster.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 12
(4,546 Views)

Did you make the text size inside the for loop smaller so it runs quicker, Yamaeda? Smiley Wink


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 10 of 12
(4,536 Views)