This is all old news but it is not something that comes to mind when I'm writing code.
Two minor changes to your code can trigger %LOOKUP to use a binary search instead of the normal linear search.
Those changes are:
Add the ASCEND keyword to the array definition
Make sure the array is loaded in ascending order
While testing with an array of approximately 3000 entries, I was seeing a 65% improvement after making those changes.
You will want to be sure to specify the last used element of your array when doing %LOOKUP
%LOOKUP( search : array : start : numelems )
Parameter 3 (start) is the index to start with, usually 1. Parameter 4 (numelems) is the number of elements to search, i.e. the number of elements you put in the array.
This is all old news but it is not something that comes to mind when I'm writing code.
Two minor changes to your code can trigger %LOOKUP to use a binary search instead of the normal linear search.
Those changes are:
While testing with an array of approximately 3000 entries, I was seeing a 65% improvement after making those changes.
You will want to be sure to specify the last used element of your array when doing %LOOKUP
%LOOKUP( search : array : start : numelems )
Parameter 3 (start) is the index to start with, usually 1. Parameter 4 (numelems) is the number of elements to search, i.e. the number of elements you put in the array.