Avoid doing OpenDevice on a handler.
[AROS-Contrib.git] / rexx / progs / rexxcps.r
blob683de803d59810ca500fd8c117787da43f9229b0
1 /* Take a measure of REXX clauses-per-second (CIPS) */
2 /* Mike Cowlishaw (MFC at VENTA) */
3 /* 1.0 17 Jan 89 Original version */
4 /* 2.0 3 Jun 89 Remove attempt to simulate commands */
5 /* 2.1 7 Oct 89 Remove use of not symbols, and correct commentary */
6 rexxcps=2.1 /* REXXCPS version */
8 /* This measure of REXX execution speed is based on an analysis of */
9 /* the dynamic mix of clauses found in a (subjectively chosen) */
10 /* collection of REXX programs (including commands, macros, and */
11 /* personal programs). Approximately 2,500,000 lines of trace */
12 /* output were analysed, and the program below recreates the */
13 /* dynamic mix of constructs found in that analysis. */
14 /* In view of the dramatic differences between systems in their */
15 /* efficiency of issuing commands, the timed loop does not issue */
16 /* commands (an 'RC=expression; PARSE' sequence is used instead). */
17 /* This program therefore measures the performance of a REXX */
18 /* implementation, exclusive of command execution overhead. */
19 /* Elapsed (user-perceived) time is used, rather than any form of */
20 /* virtual time. */
22 count=10 /* Repetition count */
23 averaging=10 /* Averaging-over count */
24 tracevar='Off' /* Trace setting (for development use) */
25 signal on novalue
26 parse source source 1 system .
27 parse version version
30 say '----- REXXCPS' rexxcps '-- Measuring REXX clauses/second -----'
31 say ' REXX version is:' version
32 say ' System is:' system
33 say ' Averaging:' averaging 'measures of' count 'iterations'
35 /* ----- Calibrate for the empty do-loop (average of 5) ----- */
36 empty=0
37 do i=1 to averaging
38 call time 'R'
39 do count; end
40 empty=time('R')+empty
41 end
42 empty=empty/averaging
44 noterm=(system='CMS'); if pos('O',tracevar)=1 then noterm=0
45 if noterm then do
46 say 'Calibration (empty DO):' empty 'secs (average of' averaging')'
47 say 'Spooling trace NOTERM'
48 'CP SPOOL CON * START NOTERM'; 'CP CLOSE CON PUR'
49 end
51 /* Now the true timer loop .. average timing again */
52 full=0
53 do i=1 to averaging
54 trace value tracevar
55 call time 'R'
56 do count;
57 /* ----- This is first of the 1000 clauses ----- */
58 flag=0; p0='b'
59 do loop=1 to 14
60 /* This is the "block" comment in loop */
61 key1='Key Bee'
62 acompound.key1.loop=substr(1234"5678",6,2)
63 if flag=acompound.key1.loop then say 'Failed1'
64 do j=1.1 to 2.2 by 1.1 /* executed 28 times */
65 if j>acompound.key1.loop then say 'Failed2'
66 if 17<length(j)-1 then say 'Failed3'
67 if j='foobar' then say 'Failed4'
68 if substr(1234,1,1)=9 then say 'Failed5'
69 if word(key1,1)='?' then say 'Failed6'
70 if j<5 then do /* This path taken */
71 acompound.key1.loop=acompound.key1.loop+1
72 if j=2 then leave
73 end
74 iterate
75 end j
76 avar.=1.0''loop
77 select
78 when flag='string' then say 'FailedS1'
79 when avar.flag.2=0 then say 'FailedS2'
80 when flag=5+99.7 then say 'FailedS3'
81 when flag then avar.1.2=avar.1.2*1.1
82 when flag==0 then flag=0
83 end
84 if 1 then flag=1
85 select
86 when flag=='ring' then say 'FailedT1'
87 when avar.flag.3=0 then say 'FailedT2'
88 when flag then avar.1.2=avar.1.2*1.1
89 when flag==0 then flag=1
90 end
91 parse value 'Foo Bar' with v1 +5 v2 .
92 trace value trace(); address value address()
93 call subroutine 'with' 2 'args', '(This is the second)'1''1
94 rc='This is an awfully boring program'; parse var rc p1 (p0) p5
95 rc='is an awfully boring program This'; parse var rc p2 (p0) p6
96 rc='an awfully boring program This is'; parse var rc p3 (p0) p7
97 rc='awfully boring program This is an'; parse var rc p4 (p0) p8
98 end loop
99 /* ----- This is last of the 1000 clauses ----- */
101 full=time('R')+full
102 trace off
104 full=full/averaging
105 if noterm then do
106 'CP CLOSE CON'; 'CP SPOOL CON * START TERM'
107 say 'Spooling now back on TERM'
110 /* Now display the statistics */
111 looptime=(full-empty)/count
112 /* Developer's statistics: */
113 if left(tracevar,1)='O' then nop; else do
115 say 'Total (full DO):' full-empty 'secs (average of' averaging ,
116 'measures of' count 'iterations)'
117 say 'Time for one iteration (1000 clauses) was:' looptime 'seconds'
119 /* And finally, the Result... */
121 say' Performance:' format(1000/looptime,,0) 'REXX clauses per second'
124 exit
127 /* Target routine for the timed CALL - called 14 times */
128 subroutine:
129 parse upper arg a1 a2 a3 ., a4
130 parse var a3 b1 b2 b3 .
131 do 1; rc=a1 a2 a3; parse var rc c1 c2 c3; end
132 return
134 novalue: if noterm then 'CP SP CON STOP TERM'
135 say "No value from line" sigl":" sourceline(sigl)