home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
PERFORM
/
SETEST.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-07-10
|
8KB
|
216 lines
{$IFDEF VER70}
{$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,P-,Q-,R-,S+,T-,V-,X+}
{$ELSE}
{$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,R-,S+,V-,X+}
{$ENDIF}
{$M 16384,0,655360}
{
Borland Pascal (Objects) 7.0.
Copyright (c) 10-7-1993 DwarFools & Consultancy by drs. Robert E. Swart.
P.O. box 799
5702 NP Helmond
The Netherlands
Code size: 6528 bytes
Data size: 714 bytes
.EXE size: 6992 bytes
-------------------------------------------------------------------------
This program provides four routines to speed up the 'in', '+', '-', and a
new inverse operation on sets. The routines are named InSet23, Include21,
Exclude23 and Inverse21. The numbers indicate the number of inline bytes
that are expanded each time the macro is called.
The speed results are as follows:
reps Bob Swart Borland speed
Include: 18192 1400 1299%
InSet: 17978 13341 135%
Exclude: 18191 1365 1333%
Inverse: 18192 1284 1416%
Note that the include and exclude macros are about 13-14 times as fast as
the regular pascal operators.
}
function InSet25(var _Set; OrdElement: Byte): Boolean;
InLine(
$58/ { pop AX }
$30/$E4/ { xor AH,AH }
$5F/ { pop DI }
$07/ { pop ES }
$89/$C3/ { mov BX,AX }
$B1/$03/ { mov CL,3 }
$D3/$EB/ { shr BX,CL }
$88/$C1/ { mov CL,AL }
$80/$E1/$07/ { and CL,$07 }
$B0/$01/ { mov AL,1 }
$D2/$E0/ { shl AL,CL }
$26/ { ES: }
$22/$01/ { and AL,BYTE PTR [DI+BX] }
$D2/$E8); { shr AL,CL }
function InSet23(var _Set; OrdL: Byte): Boolean;
InLine(
$58/ { pop AX }
$31/$DB/ { xor BX,BX }
$B1/$03/ { mov CL,3 }
$88/$C3/ { mov BL,AL }
$5F/ { pop DI }
$D3/$EB/ { shr BX,CL }
$24/$07/ { and AL,$07 }
$B1/$01/ { mov CL,1 }
$07/ { pop ES }
$91/ { xchg AX,CX }
$D2/$E0/ { shl AL,CL }
$26/ { ES: }
$22/$01/ { and AL,BYTE PTR [DI+BX] }
$D2/$E8); { shr AL,CL }
procedure Include21(var _Set; OrdElement: Byte);
InLine(
$58/ { pop AX }
$31/$DB/ { xor BX,BX }
$B1/$03/ { mov CL,3 }
$88/$C3/ { mov BL,AL }
$5F/ { pop DI }
$D3/$EB/ { shr BX,CL }
$24/$07/ { and AL,$07 }
$B1/$01/ { mov CL,1 }
$07/ { pop ES }
$91/ { xchg AX,CX }
$D2/$E0/ { shl AL,CL }
$26/ { ES: }
$08/$01); { or BYTE PTR [DI+BX],AL }
procedure Exclude23(var _Set; OrdElement: Byte);
InLine(
$58/ { pop AX }
$31/$DB/ { xor BX,BX }
$B1/$03/ { mov CL,3 }
$88/$C3/ { mov BL,AL }
$5F/ { pop DI }
$D3/$EB/ { shr BX,CL }
$24/$07/ { and AL,$07 }
$B1/$01/ { mov CL,1 }
$07/ { pop ES }
$91/ { xchg AX,CX }
$D2/$E0/ { shl AL,CL }
$F6/$D0/ { not AL }
$26/ { ES: }
$20/$01); { and BYTE PTR [DI+BX],AL }
procedure Inverse21(var _Set; OrdElement: Byte);
InLine(
$58/ { pop AX }
$31/$DB/ { xor BX,BX }
$B1/$03/ { mov CL,3 }
$88/$C3/ { mov BL,AL }
$5F/ { pop DI }
$D3/$EB/ { shr BX,CL }
$24/$07/ { and AL,$07 }
$B1/$01/ { mov CL,1 }
$07/ { pop ES }
$91/ { xchg AX,CX }
$D2/$E0/ { shl AL,CL }
$26/ { ES: }
$30/$01); { xor BYTE PTR [DI+BX],AL }
var TimerTick: Word absolute $0040:$006C;
StartTick: Word;
BobSwart,Reps: LongInt;
var S: Set of Char;
t: Char;
begin
writeln('reps Bob Swart Borland speed');
S := [];
t := '@';
write('Include: ');
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
Include21(S,60+Ord(t));
{ call function }
Inc(Reps);
until StartTick <> TimerTick;
write(Reps:8);
BobSwart := Reps;
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
S := S + [t];
{ call function }
Inc(Reps);
until StartTick <> TimerTick;
writeln(Reps:9,100.0*BobSwart/Reps:6:0,'%');
write('InSet: ');
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
if InSet23(S,Ord(t)) then
{ call function }
Inc(Reps);
until StartTick <> TimerTick;
write(Reps:8);
BobSwart := Reps;
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
if t in S then { call function }
Inc(Reps);
until StartTick <> TimerTick;
writeln(Reps:9,100.0*BobSwart/Reps:6:0,'%');
write('Exclude: ');
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
Exclude23(S,Ord(t));
Inc(Reps);
until StartTick <> TimerTick;
write(Reps:8);
BobSwart := Reps;
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
S := S - [t];
Inc(Reps);
until StartTick <> TimerTick;
writeln(Reps:9,100.0*BobSwart/Reps:6:0,'%');
write('Inverse: ');
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
Inverse21(S,Ord(t));
Inc(Reps);
until StartTick <> TimerTick;
write(Reps:8);
BobSwart := Reps;
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
if t in S then S := S - [t]
else S := S + [t];
Inc(Reps);
until StartTick <> TimerTick;
writeln(Reps:9,100.0*BobSwart/Reps:6:0,'%');
end.