Entering content frameGET RUN TIME FIELD Locate the document in its SAP Library structure

You can use the GET RUN TIME FIELD statement to measure the relative runtime of program segments in microseconds. The syntax is as follows:

Syntax

GET RUN TIME FIELD <f>.

When this statement is called initially, the value of field <f>, which should be of type I, is set to zero. Each subsequent call of the statement sets the value of field <f> to the runtime of the program that has elapsed since the statement was called first.

Note

In the client/server environment of an R/3 System, runtimes are no fixed values but can vary depending on the system load. SAP therefore recommends that you measure runtimes several times and calculate the minimum or the average from the results.

Example

DATA T TYPE I.

GET RUN TIME FIELD T.
WRITE: / 'Runtime', T.

DO 10 TIMES.
  GET RUN TIME FIELD T.
WRITE: / 'Runtime', T.
ENDDO.

The output list of this program segment might look as follows:

Runtime 0

Runtime 4.926
Runtime 5.228
Runtime 5.649
Runtime 6.100
Runtime 6.512
Runtime 6.906
Runtime 7.324
Runtime 7.724
Runtime 8.231
Runtime 8.623

After initialization, the runtime of the DO loop is added up in field T.

The best way to measure the runtime of a specific program segment is to calculate the difference between the relative runtimes before and after the segment.

Example

DATA: T1 TYPE I,
T2 TYPE I,
T TYPE P DECIMALS 2,
N TYPE I VALUE 1000.

T = 0.
DO N TIMES.
  GET RUN TIME FIELD T1.

*****************************
* Code to be tested *
*****************************

  GET RUN TIME FIELD T2.
  T2 = T2 - T1.
  T = T + T2 / N.
ENDDO.

WRITE: / 'Mean Runtime: ', T, 'microseconds'.

This example shows a DO loop that is constructed around a program segment to be tested. In this example, the program segment is just a comment. The difference of the relative runtimes after (T2) and before (T1) the program segment is measured N times. The mean value (T) is calculated from the results. The output might look as follows:

Mean Runtime:            23,40 microseconds

The output shows the offset time that results from the runtime measurement itself. This offset must be subtracted from the runtime of a real program segment.

If you replace the comment block in the program with the simple assignment

T = T.

the result might be:

Mean Runtime:            28,84 microseconds

This shows that the runtime of a simple assignment (without type conversion) is about 5 microseconds. If you assign T to a field of type C, the runtime is increased by a factor of about four due to the type conversion.

 

 

 

 

 

Leaving content frame