MOVE'ing an array  
 

 Post a new Code Sample   Modify this Code Sample

This programs compares CPU and elapsed times for three techniques for MOVE'ing one array to another (copying an array).
The three techniques are:
(1)  NATBOL (a FOR loop through the array)  (2) An array level MOVE   (3)  A string MOVE (a REDEFINE of the array)


* THIS PROGRAM DEMONSTRATES THE "COST" OF NATBOL
* CODE FOR COPYING AN ARRAY AS OPPOSED TO
* AN ARRAY MOVE AND A STRING MOVE.
*
* THE STRING MOVE IS FAR MORE EFFICIENT THAN
* THE OTHER TWO TECHNIQUES. 
*
* THE DUMMY FOR LOOP IS JUST TO SHOW THE "OVERHEAD"
* OF THE FOR LOOP WHICH IS COMMON TO ALL THREE
* OF THE TESTING LOOPS.
*
DEFINE DATA LOCAL
1 #CPU-START (I4)
1 #CPU-ELAPSED (I4)
1 #LOOP (I4)
1 #LOOP2 (I4)
1 #A (A3/1:100)
1 REDEFINE #A
  2 #A-STRING (A300)
1 #B (A3/1:100)
1 REDEFINE #B
  2 #B-STRING (A300)
END-DEFINE
*
INCLUDE AATITLER
INCLUDE AASETC
*
MOVE *CPU-TIME TO #CPU-START
SETA. SETTIME
FOR #LOOP = 1 TO 1000000
IGNORE
END-FOR
COMPUTE #CPU-ELAPSED = *CPU-TIME - #CPU-START
WRITE 5T 'DUMMY FOR LOOP: ' *TIMD (SETA.) #CPU-ELAPSED
*
MOVE *CPU-TIME TO #CPU-START
SETB. SETTIME
FOR #LOOP = 1 TO 1000000
    MOVE #A-STRING TO #B-STRING
    END-FOR
COMPUTE #CPU-ELAPSED = *CPU-TIME - #CPU-START
WRITE 5T 'STRING ' *TIMD (SETB.) #CPU-ELAPSED
*
MOVE *CPU-TIME TO #CPU-START
SETC. SETTIME
FOR #LOOP = 1 TO 1000000
FOR #LOOP2 = 1 TO 100
    MOVE #A (#LOOP2) TO #B (#LOOP2)
    END-FOR
END-FOR
COMPUTE #CPU-ELAPSED = *CPU-TIME - #CPU-START
WRITE 5T 'NATBOL: ' *TIMD (SETC.) #CPU-ELAPSED
*
MOVE *CPU-TIME TO #CPU-START
SETD. SETTIME
FOR #LOOP = 1 TO 1000000
    MOVE #A (*) TO #B (*)
    END-FOR
COMPUTE #CPU-ELAPSED = *CPU-TIME - #CPU-START
WRITE 5T 'ARRAY ' *TIMD (SETD.) #CPU-ELAPSED
*
END

************************************************************
PC OUTPUT

    PAGE #   1                    DATE:    11-02-12
    PROGRAM: ARRAY01              LIBRARY: NEWPROGS
 
    DUMMY FOR LOOP:         3          37
    STRING         5          45
    NATBOL:      1449       10471
    ARRAY       149        1485

*************************************************************    
    
MAINFRAME OUTPUT

    PAGE #   1                    DATE:    11-02-12
    PROGRAM: ARRAY01              LIBRARY: XSTRO
 
    DUMMY FOR LOOP:         6          61
    STRING        11         100
    NATBOL:      1568       12544
    ARRAY        14         122                                

Description :

There are two outputs, PC and Mainframe.

For both PC and Mainframe, the performance of the NATBOL code is terrible. It should not be used for this functionality.

On the PC and the Mainframe, the efficiency of the string MOVE is apparent. On the PC, after subtracting out the
common FOR loop, the ration is about seventy to one in favor of the string MOVE when compared with the array MOVE.
On the mainframe, after subtracting the FOR loop, the ratio is about two to one in favor of the string MOVE.

YET, in code I have seen around the world, the NATBOL code is most prevalent, followed by the array MOVE, followed by the string MOVE.


Disclaimer :

Utilities and samples shown here are not official parts of the Software AG products. These utilities and samples are not eligible for technical support through Software AG Customer Care. Software AG makes no guarantees pertaining to the functionality, scalability, robustness, or degree of testing of these utilities and samples. Customers are strongly advised to consider these utilities and samples as "working examples" from which they should build and test their own solutions

 
Search Community Websites
Natural Products
Roadmap (Aug, 2012)
NaturalONE
Natural General
Natural for Mainframes
Natural for Linux, Unix and OpenVMS
Natural for Windows
Natural Add-Ons
Terms of Use    Privacy Policy    Imprint    Copyright © 2012 Software AG    Contact Us