× 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.



On Wed, 2005-06-15 at 14:03, Wilt, Charles wrote:
> Nope.
> 
> Makes perfect sense if a high percentage of the dates are valid.  You're 
> programming to handle the exceptions.  Why waste the cycles testing dates 
> that are valid.
> 
> On the other hand, if a high percentage of dates are invalid, then one could 
> make the argument that testing first might be better.
> 
> 
> Charles Wilt

I think that even if a high percentage of the dates are invalid it would
be a better way to go: the good dates would still process correctly with
no additional overhead, and the on-error can have nested monitors inside
of it as well...

/free
  monitor ;
    myDate = %date( dateField : *USA );
  on-error ;
    monitor ;
      myDate = %date( dateField : *USA0 );
    on-error ;
      myDate = defaultDateField ;
    endmon ;
  endmon ;
/end-free

You still only perform error handling when necessary and you've covered
all your bases in an elegant fashion that performs very well.  If you
know which format is most frequent, simply put it first.  If you don't
know which is most, this would still perform better the alternative:

/free
  test(de) *USA dateField ;
  if not %error();
    myDate = %date( dateField : *USA );
  else ;
    test(de) *USA0 dateField ;
    if not %error();
      myDate = %date( dateField : *USA0 );
    else ;
      myDate = defaultDateField ;
    endif ;
  endif ;
/end-free

Let's say we encounter a date that is neither *USA or *USA0: these are
the operations that must happen to finally resolve the error:

1. TEST(DE) the format for *USA
2. Check for an error condition. (FOUND)
3. TEST(DE) the format for *USA0
4. Check for an error condition. (FOUND)
5. Assign default value.

With monitor, you have the following:
1. Try to assign as *USA. (FAILS)
2. Try to assign as *USA0. (FAILS)
3. Assign default value.

A 5-3 ratio! For 100,000 records, even if all of them were poorly
formatted, that's 500,000 operations vs. 300,000.

Now assume a record with valid *USA:

1. TEST(DE) the format for *USA
2. Check for an error condition. (NOT FOUND)
3. Assign *USA value.

vs.

1. Assign *USA value.

Now it's a 3-to-1 ratio!

Now assume 100,000 records with 75,000 bad formats and 25,000 with *USA:

TEST(DE):
5 x 75,000 = 375,000
3 X 25,000 = 75,000
TOTAL = 450,000 Operations.

MONITOR:
3 x 75,000 = 225,000
1 x 25,000 = 25,000
TOTAL = 250,000 Operations.

So even with 75% bad formats, you still do much much better with MONITOR
than TEST(DE).

Just food for thought...

Joel
http://www.rpgnext.com


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.