First, a warning. *TIMD is elapsed wall clock time. You can get rather different times depending on how busy your computer is. You might want to look at *CPU-TIME, which can be a more accurate measure, and is not as dependent on when you run a timing test.
The following program shows the use of *TIMD and *CPU-TIME
THIS PROGRAM DEMONSTRATES HOW EXPENSIVE IT IS TO EXAMINE AN ARRAY
AS OPPOSED TO EXAMINE’ING A STRING.
DEFINE DATA LOCAL
1 #STRING-TABLE (50)
2 #ARRAY (A3)
2 #DUMMY (A1) INIT ALL <‘*’>
1 REDEFINE #STRING-TABLE
2 #STRING (A200)
1 #LOOP (P9)
1 #NUMBER (P3)
1 #CPU-START (P9)
1 #CPU-ELAPSED (P9)
END-DEFINE
*
INCLUDE AATITLER
INCLUDE AASETC
*
MOVE *CPU-TIME TO #CPU-START
SETTIME
FOR #LOOP = 1 TO 300000
IGNORE
END-FOR
COMPUTE #CPU-ELAPSED = *CPU-TIME - #CPU-START
WRITE 3/10 ‘CONTROL LOOP TIME==>’ *TIMD (0200) #CPU-ELAPSED
*
MOVE *CPU-TIME TO #CPU-START
SETTIME
FOR #LOOP = 1 TO 300000
EXAMINE #STRING FOR ‘X’ GIVING NUMBER #NUMBER
*
IF #NUMBER = 0
IGNORE
END-IF
END-FOR
COMPUTE #CPU-ELAPSED = *CPU-TIME - #CPU-START
WRITE 3/10 ‘STRING TIME==>’ *TIMD (0280) #CPU-ELAPSED
*
MOVE CPU-TIME TO #CPU-START
SETTIME
FOR #LOOP = 1 TO 300000
EXAMINE #ARRAY () FOR ‘X’ GIVING NUMBER #NUMBER
*
IF #NUMBER = 0
IGNORE
END-IF
END-FOR
COMPUTE #CPU-ELAPSED = *CPU-TIME - #CPU-START
WRITE 3/10 ‘ARRAY TIME==>’ *TIMD (0400) #CPU-ELAPSED
*
END
Note that you get one extra digit by using CPU-TIME.
In either case, a FOR loop with an appropriate number of iterations is useful (especially for *TIMD) to smooth out the results. You can subtract the CONTROL LOOP TIME (see output above) from the STRING TIME and ARRAY time to get a more meaningful comparison.
Is there a possibility to “use” the *TIMESTMP system variable? What exactly is Machine-internal store clock value which is supposed to be returned with *TIMESTMP? If I subtract the START *TIMESTMP from the END *TIMESTMP and convert the resulting binary in decimal format - is this somehow in relation with the time, that has passed between START end END?
Divide RESULT by 4076829030 (meassured average Duration of 1 sek in *TIMESTMP Format with SET TIME and *TIMD)
Both Test and Production machines gave the relatively stable Value of 4076829030 when messured the duration of 1 sek with *TIMD (differences in +/- 2 milliseconds).
Just fyi, you don’t have to reinvent the wheel here, in library SYSEXT you’ll find
USR2036N Convert binary variable (B8) into numeric variable (P20)
the supplied sample will give you, for example
Convert *TIMESTMP to nano seconds using subprogram USR2036N
-----------------------------------------------------------
Start timestamp ................... D24D5372F3DE7905
Start timestamp in nano seconds ... 3699672869715431562
End timestamp ..................... D24D5372F4357805
End timestamp in nano seconds ..... 3699672869716823500
Elapsed time in milli seconds ..... 1.391938
Convert *TIMESTMP to nano seconds using copycode USR2036Z
---------------------------------------------------------
Start timestamp ................... D24D5372F3DE7905
Start timestamp in nano seconds ... 3699672869715431562
End timestamp ..................... D24D5372F4357805
End timestamp in nano seconds ..... 3699672869716823500
Elapsed time in milli seconds ..... 1.391938