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
LATEST COMMENTS
MC Press Online