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