Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What's the performance impact of a LOOKUP operation code in RPGLE?

411 views
Skip to first unread message

Ron

unread,
Aug 6, 1998, 3:00:00 AM8/6/98
to

Hello to you all,

I'am using two arrays of a 1000 date fields to store the result of my
routine "Check Date: Valid Or Not". This routine checks among the days
of the week, some calenders, to check wether a date is valid or not.
There for it has to do some database I/O and because it has to check
date's for about one million records, I store the result in the above
mentioned arrays. I check the arrays first before starting this
routine.

Still my programma is not running is fast as I want it to be ;-( !
Now I'am wondering what's the performance impact of the LOOKUP
operation code I use the check on these two arrays?

Ron

Niels Steen Madsen

unread,
Aug 6, 1998, 3:00:00 AM8/6/98
to
Hi Ron

I don't know the exact implementation of LOOKUP in RPGLE, but the
corresponding LOKUP i RPG, had serious consequences for performance.

I use it myself, but seldom in situations where performance is a
consideration. I would suggest a workfile.

Niels Steen Madsen

Ron <kou...@iaehv.nl> skrev i artiklen
<35c99a03...@nntp.iaehv.nl>...

Douglas Handy

unread,
Aug 6, 1998, 3:00:00 AM8/6/98
to
Ron,

>This routine checks among the days
>of the week, some calenders, to check wether a date is valid or not.

BTW, for days of the week (e.g. if Sunday is never a valid business
day), I would just code a subprocedure to return the day of the week
and validate it before checking the arrays and DB files with other
less obvious dates (which I presume to be holidays, etc.)

Sample day of week routines have been posted here numerous times
lately.

Doug

Douglas Handy

unread,
Aug 6, 1998, 3:00:00 AM8/6/98
to
Ron,

>Still my programma is not running is fast as I want it to be ;-( !
>Now I'am wondering what's the performance impact of the LOOKUP
>operation code I use the check on these two arrays?

The default LOOKUP operation on unordered arrays is not terribly
efficient, as it always searches all defined elements whether used or
not.

You can increase the efficiency by limiting the number of elements
searched to only those used by filling the array from the back to the
front, then specifing the index of the first significant entry on the
LOOKUP operation. In other words, instead of keeping a field which
gets incremented to tell you where to insert a new value, initialize
the field to %elem( array ) then decrement it appropriately. On the
LOOKUP operation, use array(field) in factor2 instead of just the
array name. This causes the search to begin at the element specified,
which can dramatically lower the number of iterations.

HTH,
Doug

Tim

unread,
Aug 7, 1998, 3:00:00 AM8/7/98
to
You should look into using a User Index (*USRIDX?) in System API reference.
They are user objects that were designed specifically for the purpose you
describe. And they are faster than database files.

Ron wrote in message <35c99a03...@nntp.iaehv.nl>...


>
>Hello to you all,
>
>I'am using two arrays of a 1000 date fields to store the result of my

>routine "Check Date: Valid Or Not". This routine checks among the days


>of the week, some calenders, to check wether a date is valid or not.

>There for it has to do some database I/O and because it has to check
>date's for about one million records, I store the result in the above
>mentioned arrays. I check the arrays first before starting this
>routine.
>

>Still my programma is not running is fast as I want it to be ;-( !
>Now I'am wondering what's the performance impact of the LOOKUP
>operation code I use the check on these two arrays?
>

>Ron

Craig & Nancy Rutledge

unread,
Aug 7, 1998, 3:00:00 AM8/7/98
to
Lookup is the one of the SLOWEST performing opcodes in RPG. Suggest
loading arrays backwards, then always start your lookup index with the last
element loaded.

This can dramatically speed up searches especially if you are getting a lot
of 'no hits'.

Otherwise, suggest using data base I/O. I have been experimenting with
user indexes but so far, they seem to be more effort than they are
apparently worth just to replace a lookup.

Gernot B Längle

unread,
Aug 8, 1998, 3:00:00 AM8/8/98
to
ASAIK, If you keep the arrays sorted, lookup uses a binary search
technique and is reasonably fast, but with unsorted arrays it uses a
sequential method which is inherently slow.

Ron wrote:
>
> Hello to you all,
>
> I'am using two arrays of a 1000 date fields to store the result of my
> routine "Check Date: Valid Or Not". This routine checks among the days
> of the week, some calenders, to check wether a date is valid or not.
> There for it has to do some database I/O and because it has to check
> date's for about one million records, I store the result in the above
> mentioned arrays. I check the arrays first before starting this
> routine.
>
> Still my programma is not running is fast as I want it to be ;-( !
> Now I'am wondering what's the performance impact of the LOOKUP
> operation code I use the check on these two arrays?
>
> Ron

--
Gernot Langle
PARAS Solutions, Inc.
http://www.parassolutions.com
mailto:gla...@parassolutions.com

boo...@ibm.net

unread,
Aug 8, 1998, 3:00:00 AM8/8/98
to
Additionally to the other suggestions, as you load the array decrement a
counter (i.e. "I") from the array size. Once you have loaded the array,
this will tell you how many elements of the array are actually empty.
Sort the array in ascending order. Do your lookup as LOKUP AR,I. That
way the lookup will start in the first non-empty array element.

In <35CC7C56...@tc.umn.edu>, on 08/08/98

at 11:27 AM, "Gernot B L ngle" <lang...@tc.umn.edu> said:

>ASAIK, If you keep the arrays sorted, lookup uses a binary search
>technique and is reasonably fast, but with unsorted arrays it uses a
>sequential method which is inherently slow.

>Ron wrote:
>>
>> Hello to you all,
>>
>> I'am using two arrays of a 1000 date fields to store the result of my
>> routine "Check Date: Valid Or Not". This routine checks among the days
>> of the week, some calenders, to check wether a date is valid or not.
>> There for it has to do some database I/O and because it has to check
>> date's for about one million records, I store the result in the above
>> mentioned arrays. I check the arrays first before starting this
>> routine.
>>
>> Still my programma is not running is fast as I want it to be ;-( !
>> Now I'am wondering what's the performance impact of the LOOKUP
>> operation code I use the check on these two arrays?
>>
>> Ron


--
-----------------------------------------------------------
boo...@ibm.net
Booth Martin
-----------------------------------------------------------


Douglas Handy

unread,
Aug 8, 1998, 3:00:00 AM8/8/98
to
Gernot,

>ASAIK, If you keep the arrays sorted, lookup uses a binary search
>technique and is reasonably fast, but with unsorted arrays it uses a
>sequential method which is inherently slow.

Not so. RPG never uses a binary search, even with sorted arrays. Or,
at least it never used to before the rewrite of the compiler for ILE
RPG. It is possible IBM changed this, but I consider it unlikely.

I have never found LOOKUP to be reasonably fast, except with small
arrays.

Doug

Mike Cravitz

unread,
Aug 9, 1998, 3:00:00 AM8/9/98
to
>ASAIK, If you keep the arrays sorted, lookup uses a binary search
>technique and is reasonably fast, but with unsorted arrays it uses a
>sequential method which is inherently slow.

You mean I went to all the trouble of showing the binary search
algorithm for nothin'? I can't find this fact documented anywhere. Are
you quite certain it's true?

Mike Cravitz

NEWS/400 Technical Editor

Gernot B Längle

unread,
Aug 9, 1998, 3:00:00 AM8/9/98
to
I'm not certain about the actual coding in the RPG compilers and could
not find any specific reference to it in the RPG manuals other than the
one below which may help the original poster to speed up the search:

If only an equal indicator (positions 75-76) is used, the LOOKUP
operation will search the entire array or table. If your array or
table is in ascending sequence and you want only an equal
comparison,
you can avoid searching the entire array or table by specifying a
high
indicator.

However, with a sorted array, it would certainly be possible (and much
more efficient) to implement LOOKUP utilizing a binary search algorithm
- perhaps someone at IBM in RPG compiler development could provide a
definite answer?

--

bmo...@ca.ibm.com

unread,
Aug 10, 1998, 3:00:00 AM8/10/98
to
LOOKUP still uses a sequential search even for ILE RPG. This is probably
because some searches are for less-than-or-equal, or greater-than etc, and
even with search for equality there's no requirement for unique elements, and
the search has to find the same element that it always did with RPG III.
Even so it would be possible for LOOKUP to use a binary search to find one
element satisfying the search and then sequentially search backwards or
forwards to find the right one (I can't promise that we'll change the
implementation, though). -- Barbara Morris IBM Toronto Lab RPG Compiler
Development

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum

0 new messages