BrianGarland / blog

This is my blog
1 stars 0 forks source link

Improved performance for %LOOKUP #6

Open BrianGarland opened 3 years ago

BrianGarland commented 3 years ago

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:

  1. Add the ASCEND keyword to the array definition
  2. 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.