From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search for all Elements in Array that Equal X

Variants, by the way, will also have different characteristics for both creation and lookup time. If you make your list once and get many times, then using variants or maintaining a sorted list would be best. If you are constantly forming and reforming these arrays you might end up getting a faster overall rate by going with the thing that has a slower lookup. Further, its hard to be sure what takes the most time. Getting and setting variant attributes requires string manipulations (for the name lookup) and the memory allocation could take more time than the entire search process. On the other hand the same is true of your current code -- building up an array of unknown size could be quite slow (and of course the solution in your case would be preallocate and subset the array).

 

 

Bottom line is if it works don't change it until you know you have to. Even Jeff's point (pull the compare outside the loop) is unnecessary even if its the right thing to do -- the compiler should take care of that one for you...in theory. Anyway, are you having performance problems or just trying to learn something new? A modern i5 should take microseconds to search through a 700-element array.

0 Kudos
Message 11 of 11
(468 Views)