LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Searching Large 1D String Array Painfully Slow.

Solved!
Go to solution

More like 10 seconds. Try and wire the index to a boolean comparison and see what happens. 

0 Kudos
Message 11 of 23
(1,597 Views)

I am searching large Array for a match in the generated array, it's that simple. This doesn't work either. I have isolated the cause. If you wire the index to try and get the value, it takes 10 seconds instead of  milliseconds. Labview  2020, same in 2016.Vi Search 1.png

0 Kudos
Message 12 of 23
(1,593 Views)

I'm with RavensFan.  It's time to back up, slow down and describe this problem clearly and thoroughly.

 

You say, "I am searching large Array for a match in the generated array, it's that simple."  But your *code* shows you doing the opposite -- searching through the generated array for each of the elements contained in the large fixed array.   That's 500k searches through a 50k array and you're trying to do it once a second?

 

From the limited info you've given so far, this *sounds* like a problem that would be better off using a Map rather than an array.  A Map's lookup performance is logarithmic with size rather than linear, and with a 500k size that's likely to make a pretty huge difference.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 13 of 23
(1,584 Views)

I am generating random words 50 k per second. Looking for a match in the large array that is read from file but it's all irreverent. There appears to be a bug.  No matter what I search for, anything is size, wiring the index to a condition or output to for loop kills the search speed by a factor of 1000. 

0 Kudos
Message 14 of 23
(1,577 Views)

I have tried it reversed as you suggested and the problem the remains. The issue is not apparent until you try and wire the index terminal to anything, including an indicator. Yes, once a second. The large file is read from disk and shift registered. I want to see if any of the generated words matched the file. You're correct that it's reversed but I was just playing around to observe behavior. You can reproduce the behavior if you wire the index terminal from the search 1d. 

0 Kudos
Message 15 of 23
(1,564 Views)

Very easy to fix this. Sort your 500k array (or load it already sorted) then use a binary search to find the random words.I get 100-1000x speedup, and it should be fairly constant for all words, whereas the ordinary Search varies depending on where the word is in the array.

0 Kudos
Message 16 of 23
(1,558 Views)

Thanks, the Big Array is sorted. Is there an example of a binary search? 

0 Kudos
Message 17 of 23
(1,552 Views)
Solution
Accepted by n2new

@n2new wrote:

Thanks, the Big Array is sorted. Is there an example of a binary search? 


If you're in LabVIEW 2020, you can use the Search Sorted 1D Array.vim.

Message 18 of 23
(1,547 Views)

Here you go. It's modified from one I found, but not sure where, so apologies if I haven't acknowledged someone for it. BinarySearch.png

0 Kudos
Message 19 of 23
(1,545 Views)

I was looking at that function. How to convert String array to polymorphic? 

0 Kudos
Message 20 of 23
(1,540 Views)