You may recall the outline of a timing procedure in Part Two (see 10.7.1 Evaluation).
This chapter gives the complete version of this example.
The information missing from the outline was how to determine the system time and use this to calculate the time taken by calls to Eval
.
So the things to notice about this example are:
DateStamp
(from the `dos.library').
(You really need the Rom Kernel Reference Manuals and the AmigaDOS Manual to understand the system functions.)
datestamp
and the constant TICKS_PER_SECOND
.
(There are fifty ticks per second.)
repeat
procedure to do Eval
a decent number of times for each expression (so that some time is taken up by the calls!).
offset
the first time the test
procedure is called.
The expression 0 should take a negligible amount of time, so the number of ticks timed is actually the time taken by the procedure calls and loop calculations.
Subtracting this time from the other times gives a fair view of how long the expressions take, relative to one another.
(Thanks to Wouter for this offset idea.)
Forbid
and Permit
to turn off multi-tasking temporarily, making the CPU calculate only the expressions (rather than dealing with screen output, other programs, etc.).
CtrlC
and CleanUp
to allow the user to stop the program if it gets too boring...
LARGE
(using OPT
) to produce an executable that uses the large data and code model.
This seems to help make the timings less susceptible variations due to, for instance, optimisations, and so better for comparison.
See the Reference Manual for more details.
Also supplied are some example outputs.
The first was from an A1200 with 2MB Chip RAM and 4MB Fast RAM.
The second was from an A500Plus with 2MB Chip RAM.
Both used the constant LOTS_OF_TIMES
as 500,000, but you might need to increase this number to compare, for instance, an A4000/040 to an A4000/030.
However, 500,000 gives a pretty long wait for results on the A500.
MODULE 'dos/dos' CONST TICKS_PER_MINUTE=TICKS_PER_SECOND*60, LOTS_OF_TIMES=500000 DEF x, y, offset PROC fred(n) DEF i i:=n+x ENDPROC /* Repeat evaluation of an expression */ PROC repeat(exp) DEF i FOR i:=0 TO LOTS_OF_TIMES Eval(exp) /* Evaluate the expression */ ENDFOR ENDPROC /* Time an expression, and set-up offset if not done already */ PROC test(exp, message) DEF t IF offset=0 THEN offset:=time(`0) /* Calculate offset */ t:=time(exp) WriteF('\s:\t\d ticks\n', message, t-offset) ENDPROC /* Time the repeated calls, and calculate number of ticks */ PROC time(x) DEF ds1:datestamp, ds2:datestamp Forbid() DateStamp(ds1) repeat(x) DateStamp(ds2) Permit() IF CtrlC() THEN CleanUp(1) ENDPROC ((ds2.minute-ds1.minute)*TICKS_PER_MINUTE)+ds2.tick-ds1.tick PROC main() x:=9999 y:=1717 test(`x+y, 'Addition') test(`y-x, 'Subtraction') test(`x*y, 'Multiplication') test(`x/y, 'Division') test(`x OR y, 'Bitwise OR') test(`x AND y, 'Bitwise AND') test(`x=y, 'Equality') test(`x<y, 'Less than') test(`x<=y, 'Less than or equal') test(`y:=1, 'Assignment of 1') test(`y:=x, 'Assignment of x') test(`y++, 'Increment') test(`IF FALSE THEN y ELSE x, 'IF FALSE') test(`IF TRUE THEN y ELSE x, 'IF TRUE') test(`IF x THEN y ELSE x, 'IF x') test(`fred(2), 'fred(2)') ENDPROC
Here's the output from the A1200:
Addition: 22 ticks Subtraction: 22 ticks Multiplication: 69 ticks Division: 123 ticks Bitwise OR: 33 ticks Bitwise AND: 27 ticks Equality: 44 ticks Less than: 43 ticks Less than or equal: 70 ticks Assignment of 1: 9 ticks Assignment of x: 38 ticks Increment: 23 ticks IF FALSE: 27 ticks IF TRUE: 38 ticks IF x: 44 ticks fred(2): 121 ticks
Compare this to the output from the A500Plus:
Addition: 118 ticks Subtraction: 117 ticks Multiplication: 297 ticks Division: 643 ticks Bitwise OR: 118 ticks Bitwise AND: 117 ticks Equality: 164 ticks Less than: 164 ticks Less than or equal: 164 ticks Assignment of 1: 60 ticks Assignment of x: 102 ticks Increment: 134 ticks IF FALSE: 118 ticks IF TRUE: 164 ticks IF x: 193 ticks fred(2): 523 ticks
Evidence, if it were needed, that the A1200 is roughly five times faster than an A500, and that's not using the special 68020 CPU instructions!
Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.