# Measuring natural performance in ms (miliseconds)

**URL:** <https://techcommunity.softwareag.com/t/measuring-natural-performance-in-ms-miliseconds/193806>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-Code-Samples, Inside-Natural-and-Performance-Hints\
**Created:** [March 24, 2017, 9:11am UTC](https://techcommunity.softwareag.com/t/measuring-natural-performance-in-ms-miliseconds/193806 "2017-03-24T09:11:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rok\_Purkeljc](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Rok\_Purkeljc](https://techcommunity.softwareag.com/u/Rok_Purkeljc)\
**Post date:** [March 24, 2017, 9:11am UTC](https://techcommunity.softwareag.com/t/measuring-natural-performance-in-ms-miliseconds/193806/1 "2017-03-24T09:11:27Z")

</div>

Hi all,

Is there a way to measure the precise exectution duration of a certain codeblock in natural code with a precision of milliseconds?

As it seems, it is only possible to determine the acuracy in tenth of a second with SET TIME and \*TIMD…

Regards,  
Rok

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [March 24, 2017, 12:22pm UTC](https://techcommunity.softwareag.com/t/measuring-natural-performance-in-ms-miliseconds/193806/2 "2017-03-24T12:22:43Z")

</div>

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

```
PAGE # 1 DATE: 11/20/10
PROGRAM: EXAMIN02 LIBRARY: BOST-PER

     CONTROL LOOP TIME==> 4 43

     STRING TIME==> 18 177

     ARRAY TIME==> 24 241

```

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.

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [March 24, 2017, 4:01pm UTC](https://techcommunity.softwareag.com/t/measuring-natural-performance-in-ms-miliseconds/193806/3 "2017-03-24T16:01:45Z")

</div>

Too bad that \*CPU-TIME is not available in all mainframe environments, such as under CICS.

---

<div class="post-metadata">

**Author:** ![Rok\_Purkeljc](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Rok\_Purkeljc](https://techcommunity.softwareag.com/u/Rok_Purkeljc)\
**Post date:** [March 27, 2017, 6:59am UTC](https://techcommunity.softwareag.com/t/measuring-natural-performance-in-ms-miliseconds/193806/4 "2017-03-27T06:59:15Z")

</div>

> [@Ralph Zbrog](#):
>
> Too bad that \*CPU-TIME is not available in all mainframe environments, such as under CICS.

Correct… Under z/VSE \*CPU-TIME is a constant 0!

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?

Regards,  
Rok

---

<div class="post-metadata">

**Author:** ![Rok\_Purkeljc](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Rok\_Purkeljc](https://techcommunity.softwareag.com/u/Rok_Purkeljc)\
**Post date:** [March 27, 2017, 10:43am UTC](https://techcommunity.softwareag.com/t/measuring-natural-performance-in-ms-miliseconds/193806/5 "2017-03-27T10:43:45Z")

</div>

OK got it up and working…

1. Convert Starting \*TIMESTMP TO decimal
2. Convert Finish \*TIMESTMP TO decimal
3. Subtract Start from Finish giving RESULT
4. 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).

I’ll use this for now…

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [March 27, 2017, 12:21pm UTC](https://techcommunity.softwareag.com/t/measuring-natural-performance-in-ms-miliseconds/193806/6 "2017-03-27T12:21:20Z")

</div>

1 Second is exactly 4.096.000.000 in STCK format (which \*TIMESTMP is based on)

---

<div class="post-metadata">

**Author:** ![Rok\_Purkeljc](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@Rok\_Purkeljc](https://techcommunity.softwareag.com/u/Rok_Purkeljc)\
**Post date:** [March 27, 2017, 12:23pm UTC](https://techcommunity.softwareag.com/t/measuring-natural-performance-in-ms-miliseconds/193806/7 "2017-03-27T12:23:51Z")

</div>

> [@Wolfgang Winter](#):
>
> 1 Second is exactly 4.096.000.000 in STCK format (which \*TIMESTMP is based on)

Hello Wolfgang,

grazie!🙂

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [March 28, 2017, 6:55am UTC](https://techcommunity.softwareag.com/t/measuring-natural-performance-in-ms-miliseconds/193806/8 "2017-03-28T06:55:19Z")

</div>

Just fyi, you don’t have to reinvent the wheel here, in library SYSEXT you’ll find

```auto
USR2036N Convert binary variable (B8) into numeric variable (P20)
```

the supplied sample will give you, for example

```auto
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               
```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:38pm UTC](https://techcommunity.softwareag.com/t/measuring-natural-performance-in-ms-miliseconds/193806/9 "2021-04-02T15:38:09Z")

</div>


