LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching a large array for data

I have a large array that I want to search for data and the for loop is too slow for practical purposes. Does CVI have a quicker method to find data in an array. I'm thinking of something similar to the find function in Matlab.
0 Kudos
Message 1 of 11
(4,060 Views)

The 'for' loop language construct is as efficient as you're going to get, for iterating through data. I would suggest that if you can maintain your data in sorted order (i.e. order is not inherently important to the data), then you can do a binary search on your data, instead of a linear search. What kind of data do you have? Could your comparision operation be expensive? Can you optimize away some data copies or pointer dereferences?

 

Have you tried the release configuration? The debug configuration can be slower, and if you're running in the debugger and have watch expressions, you'll run WAY slower.

 

Mert A.

National Instruments

0 Kudos
Message 2 of 11
(4,056 Views)
Order is important. I am running in the debugger and need to integrate in it. Is there a way to temporary disable the debugger for the for loop only?
0 Kudos
Message 3 of 11
(4,054 Views)

If the debug build is slower, it would probably be due to runtime checks that get built into the code. You cannot disable these for a particular span of code, but you could disable runtime checking for your whole program by setting "Debuging level" to "No run-time checking" in the Options>>Build Options dialog.

 

However, I really don't think that's the way to solve your problem. Could you post the code for the loop that's too slow? In what sense is the loop too slow? Maybe with some specific details about your data, what you're doing, and what kind of response you need, we can figure out a way to optimize.

 

Mert A.

National Instruments

0 Kudos
Message 4 of 11
(4,052 Views)
Completely disabling the debugger is out of the question. Are you sure there is no function similar to DisableBreakOnLibraryErrors that could be called? Is there any function in the advanced analysis library that can give me arrays of all elements that meet certain bit mask criteria?
0 Kudos
Message 5 of 11
(4,047 Views)

Setting the debugging level to "no run-time checking" does not completely disable the debugger. You can still set breakpoints, view variable values, etc. -- you just don't have automatic safety checks (pointer arithmetic, array bounds, etc) compiled in. These checks are either compiled in, or they're not, and there is no function you can call to bypass them.

 

I do not know of any such analysis function.

 

Mert A.

National Instruments.

0 Kudos
Message 6 of 11
(4,045 Views)
What about a #xxx conditional compiler type of exclusion?
0 Kudos
Message 7 of 11
(4,043 Views)

Sorry, no. There is no such pragma to toggle the inclusion of runtime checks.

 

Have you actually noticed a significant difference between the performance of the release and debug configurations? That would be the first thing to try, because if the release configuration still seems slow, then you know that you have to do some actual code optimization.

 

Mert A.

National Instruments

0 Kudos
Message 8 of 11
(4,040 Views)
I just tried running it in release mode. Wow, the difference in time is huge. I could probably construct a DLL to run just this function in release. Can you think of a better way to do this? Do you know where I can find an example of how to write and call it?
0 Kudos
Message 9 of 11
(4,036 Views)

If you want part of your program in release mode while the rest is in debug mode, then I think the DLL route may be the only way to go. In the samples directory, I'd check out dll\basic. It should be what you need. Take a look at the readmes for step-by-step instructions.

 

Mert A.
National Instruments

0 Kudos
Message 10 of 11
(4,033 Views)