home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-12-11 | 1.5 KB | 51 lines | [TEXT/PJMM] |
- program TestCheckSum;
-
- function CheckSum (h: Handle): LONGINT;
- {Returns the sum of all bytes in a handle, ignoring integer overflow. }
- {A nil handle and an empty handle both return a sum of zero. }
- {Inner loop is 34 cycles. Should run at about 7 seconds/MB on a Mac Plus. }
- {Could be recoded with a 24 cycle inner loop, but would larger and less clear. }
- inline
- $205F, { move.l (a7)+,a0 ;the handle }
- $2208, { move.l a0,d1 ;is it nil? }
- $671A, { beq @3 ;yes - bail out }
- $A025, { _GetHandleSize ;size to D0 }
- $4281, { clr.l d1 ;clear accumulator }
- $4282, { clr.l d2 ;clear byte extender }
- $2050, { movea.l (a0),a0 ;dereference }
- $51C8, $000A, {@1 dbra d0,@2 ;done? (partially) }
- $0480, $0001, $0000, { subi.l $10000,d0 ;yes - fix hi word }
- $6B06, { bmi @3 ;done? (really) }
- $1418, {@2 move.b (a0)+,d2 ;no, get next byte }
- $D282, { add.l d2,d1 ;accumulate it }
- $60EE, { bra @1 ;repeat }
- $2E81; {@3 move.l d1,(a7) ;tuck result }
-
- const
- blockSize = $10000; {64K}
- howMany = 16; {… times 16 is 1MB}
-
- var
- h: Handle;
- s, t: LONGINT;
- i: INTEGER;
-
- begin
- ShowText;
-
- h := GetResource('CODE', 1);
- s := CheckSum(h);
- writeln(s);
-
- h := NewHandleClear(blockSize);
- if h <> nil then
- begin
- t := TickCount;
- for i := 1 to howMany do
- s := CheckSum(h);
- t := TickCount - t;
- writeln(s, ' ', howMany * blockSize, ' ', t / 60 : 0 : 1);
- end
- else
- writeln('No room for time test.');
- end.