Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timer services

Status
Not open for further replies.

dietmar0609

Programmer
Nov 25, 2008
8
FR

Hi,

I want to mesure the execution time of a pgm in micro or milli seconds.

I tried time("R") and time ("E").

As result I always get .000000 secs.

How should the instructions look like ????

Thx ...... Dietmar

 
Look at this example:

stopwatch.rex
Code:
[COLOR=#0000ff]/* stopwatch - program */[/color] 
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"Press <Enter> to Start"[/color] 
[COLOR=#804040][b]pull[/b][/color] Enter 

[COLOR=#804040][b]call[/b][/color][COLOR=#008080] TIME[/color] [COLOR=#ff00ff]"R"[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"Now measuring time ! ..."[/color]

[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"Press <Enter> to Stop"[/color]
[COLOR=#804040][b]pull[/b][/color] Enter 

[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"Elapsed Time:"[/color] [COLOR=#008080]TIME([/color][COLOR=#ff00ff]"R"[/color][COLOR=#008080])[/color] [COLOR=#ff00ff]"sec"[/color]

Output:
Code:
C:\Users\Roman\Work>rexx stopwatch.rex
Press <Enter> to Start
[COLOR=red]Here I pressed <Enter>[/color]
Now measuring time ! ...
Press <Enter> to Stop
[COLOR=red]Here I pressed <Enter>[/color]
Elapsed Time: 1.875000 sec
 
Here is another example - computation time of fibonacci numbers: elapsed_time.rex

Code:
[COLOR=#0000ff]/* Main program */[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]" n | fibonacci | time (seconds)"[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"-------------------------------"[/color] 
[COLOR=#804040][b]do[/b][/color] n [COLOR=#804040][b]=[/b][/color] 1[COLOR=#804040][b] to [/b][/color]30 
  [COLOR=#804040][b]call[/b][/color][COLOR=#008080] TIME[/color] [COLOR=#ff00ff]"R"[/color]
  fib [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]fibonacci([/color]n[COLOR=#008080])[/color]
  time_elapsed [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]TIME([/color][COLOR=#ff00ff]"R"[/color][COLOR=#008080])[/color]
  [COLOR=#804040][b]say[/b][/color] [COLOR=#008080]right([/color]n[COLOR=#804040][b],[/b][/color]2[COLOR=#804040][b],[/b][/color]0[COLOR=#008080])[/color][COLOR=#804040][b]||[/b][/color][COLOR=#ff00ff]" | "[/color][COLOR=#804040][b]||[/b][/color][COLOR=#008080]right([/color]fib[COLOR=#804040][b],[/b][/color]9[COLOR=#008080])[/color][COLOR=#804040][b]||[/b][/color][COLOR=#ff00ff]"  | "[/color][COLOR=#804040][b]||[/b][/color]time_elapsed
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]exit[/b][/color]

[COLOR=#0000ff]/* Functions */[/color]
[COLOR=#008080]fibonacci[/color]: [COLOR=#804040][b]procedure[/b][/color]
[COLOR=#804040][b]parse arg[/b][/color] n
[COLOR=#804040][b]select[/b][/color]
[COLOR=#804040][b]  when [/b][/color]n [COLOR=#804040][b]=[/b][/color] 1[COLOR=#804040][b] then [/b][/color]
     fib [COLOR=#804040][b]=[/b][/color] 1     
[COLOR=#804040][b]  when [/b][/color]n [COLOR=#804040][b]=[/b][/color] 2[COLOR=#804040][b] then [/b][/color]
     fib [COLOR=#804040][b]=[/b][/color] 1
[COLOR=#804040][b]  otherwise [/b][/color]
     fib [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]fibonacci([/color]n[COLOR=#804040][b]-[/b][/color]1[COLOR=#008080])[/color] [COLOR=#804040][b]+[/b][/color] [COLOR=#008080]fibonacci([/color]n[COLOR=#804040][b]-[/b][/color]2[COLOR=#008080])[/color]
  [COLOR=#804040][b]end[/b][/color] 
[COLOR=#804040][b]return[/b][/color] fib

Output:
Code:
C:\Users\Roman\Work>elapsed_time.rex
 n | fibonacci | time (seconds)
-------------------------------
01 |         1  | 0
02 |         1  | 0
03 |         2  | 0
04 |         3  | 0
05 |         5  | 0
06 |         8  | 0
07 |        13  | 0
08 |        21  | 0
09 |        34  | 0
10 |        55  | 0
11 |        89  | 0
12 |       144  | 0
13 |       233  | 0
14 |       377  | 0
15 |       610  | 0
16 |       987  | 0
17 |      1597  | 0
18 |      2584  | 0.016000
19 |      4181  | 0.016000
20 |      6765  | 0.015000
21 |     10946  | 0.032000
22 |     17711  | 0.062000
23 |     28657  | 0.094000
24 |     46368  | 0.140000
25 |     75025  | 0.235000
26 |    121393  | 0.375000
27 |    196418  | 0.625000
28 |    317811  | 1.015000
29 |    514229  | 1.594000
30 |    832040  | 2.610000
 
hi mikrom

Thx for your rapid answer! Very helpful

Happy new year to you and your family

Dietmar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top