× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



There are two ways to check the array that I am aware of. LOOKUP and %LOOKUP. The difference in performance appears to be a factor of 10. Is that to be expected in your opinion? Can LOOKUP take 25 minutes to run, and %LOOKUP take 4 minutes?

Depends on how you're using %LOOKUP. If you're using it on an array that's been sorted, and has the "ASCEND" or "DESCEND" keyword coded on the array definition, then you're doing a binary search lookup -- in which case it doesn't surprise me one bit that %LOOKUP is 10 times faster than LOOKUP.


The LOOKUP op-code (or %LOOKUP without ASCEND/DESCEND/SORT) is the same thing (more or less) as looping through the array (with a DO or FOR loop) and checking each array element to see if it matches. Much slower.


Of course, %LOOKUP won't compile to V4R2 anyway. So, what say you? How to solve this pig of a performer?

If you want to continue to use an array, you could consider using the bsearch() API (from the ILE C runtime library) it'll perform similarly to the way %LOOKUP works.


Otherwise, consider at least trying using an indexed access method, such as a database file w/CHAIN operation, or a user index. Although they require disk access, which will slow it down, the algorithm for a keyed lookup is much smarter than a linear "loop through all the elements" type search operation. Of course, YMMV... Sometimes it'll be faster, sometimes it wont.

HTH

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.