Correctly Size Numeric Fields

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

It's a known fact that the RPG multiply (MULT) and divide (DIV) operations do not perform as well as the other arithmetic operations. (See "The Truth About RPG Performance Coding Techniques," MC, September 1993.) However, these operations do not have to detract from CPU performance as much as you might think. The greatest impact on CPU overhead when using the multiply and divide op codes comes from not sizing the result field correctly.

By correctly sized, I mean that the result field is large enough to hold the entire contents of the result of the operation. If your result field is correctly sized, then the multiply and divide operations do not use very much CPU time. If the result field is undersized, then the program must invoke a size exception handler. The size exception handler-not the multiply or divide operation-is the process that uses up most of the CPU time.

Here is an example. I performed the following tests on a model F70 processor. The first test is a program that loops 100,000 times. Inside the loop, I performed the common date conversion routine shown in 1. The date result field in this example has a length of 15 with 5 decimal positions, which is large enough to hold the result without overflowing. This test took .8 CPU second to complete.

Here is an example. I performed the following tests on a model F70 processor. The first test is a program that loops 100,000 times. Inside the loop, I performed the common date conversion routine shown in Figure 1. The date result field in this example has a length of 15 with 5 decimal positions, which is large enough to hold the result without overflowing. This test took .8 CPU second to complete.

Test 2 is identical to test 1, except that the date field is defined with a length of 6 with 0 decimal positions (see 2). This test took 8.4 CPU seconds to complete. The massive difference in CPU time is directly related to invoking the size exception handler.

Test 2 is identical to test 1, except that the date field is defined with a length of 6 with 0 decimal positions (see Figure 2). This test took 8.4 CPU seconds to complete. The massive difference in CPU time is directly related to invoking the size exception handler.

The same tests were performed on the divide op code, and the test results were identical to those of the multiply operations.

Any multiply or divide operation uses more CPU than a simple add operation. If the program must invoke the size exception handler, the impact on performance is much greater. The biggest culprits of undersized result fields are date conversion routines and operations using decimal fields. If you do not specify enough decimal places to hold the entire result, the size exception handler is invoked.


Correctly Size Numeric Fields

Figure 1 Date Conversion with Correctly Sized Result Field

 *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 C 011293 MULT 10000.01 YMD 155 
Correctly Size Numeric Fields

Figure 2 Date Conversion with Incorrectly Sized Result Fiel

 *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 C 011293 MULT 10000.01 YMD 60 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: