home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PERFORM / TESTSET.PAS < prev    next >
Pascal/Delphi Source File  |  1993-03-28  |  4KB  |  128 lines

  1. {$IFDEF VER70}
  2. {$A+,B-,D+,E-,F-,G-,I-,L+,N-,O-,P-,Q-,R-,S+,T-,V-,X+}
  3. {$ELSE}
  4. {$A+,B-,D+,E-,F-,G-,I-,L+,N-,O-,R-,S+,V-,X+}
  5. {$ENDIF}
  6. {$M 16384,0,655360}
  7. var TimerTick: Word absolute $0040:$006C;
  8.     StartTick: Word;
  9.     Reps,Normaliseer: LongInt;
  10.  
  11. Type CharSet = Set of Char;
  12. Var CSet: CharSet;
  13.     Buffer: Array[1..32767] of Char;
  14.     i: Integer;
  15.     C: Char;
  16.  
  17.     function InSet(var _Set; OrdEl: Byte): Boolean;
  18.     var __Set: Array[0..31] of Byte absolute _Set;
  19.     begin
  20.       InSet := Boolean((__Set[OrdEl SHR 3] SHR (OrdEl AND $07)) AND $01)
  21.     end {InSet};
  22.  
  23.     function InSet25(var _Set; OrdElement: Byte): Boolean;
  24.     { Deze inline macro is sneller dan de normale 'in', behalve
  25.       indien gebruik wordt gemaakt van 'small sets' die uit 16
  26.       elementen of minder bestaan.
  27.     }
  28.     InLine(
  29.       $58/         {   pop   AX                   }
  30.       $30/$E4/     {   xor   AH,AH                }
  31.       $5F/         {   pop   DI                   }
  32.       $07/         {   pop   ES                   }
  33.       $89/$C3/     {   mov   BX,AX                }
  34.       $B1/$03/     {   mov   CL,3                 }
  35.       $D3/$EB/     {   shr   BX,CL                }
  36.       $88/$C1/     {   mov   CL,AL                }
  37.       $80/$E1/$07/ {   and   CL,$07               }
  38.       $B0/$01/     {   mov   AL,1                 }
  39.       $D2/$E0/     {   shl   AL,CL                }
  40.       $26/         {   ES:                        }
  41.       $22/$01/     {   and   AL,BYTE PTR [DI+BX]  }
  42.       $D2/$E8);    {   shr   AL,CL                }
  43.  
  44. begin
  45.   CSet := ['b','o','l','e','s','i','a','n'];
  46.   for i:=1 to SizeOf(Buffer) do
  47.   begin
  48.     Buffer[i] := Char(Ord('a')+Random(26)); { Init Buffer }
  49.     if (Buffer[i] in CSet) <> InSet25(CSet,Ord(Buffer[i])) then { Error }
  50.     begin
  51.       writeln('Error InSet25 ',Buffer[i],' not correct at: ',i);
  52.       Halt(1)
  53.     end;
  54.     if (Buffer[i] in CSet) <> InSet(CSet,Ord(Buffer[i])) then { Error }
  55.     begin
  56.       writeln('Error InSet ',Buffer[i],' not correct at: ',i);
  57.       Halt(1)
  58.     end
  59.   end;
  60.  
  61.   i := 0;
  62.   Reps := 0;
  63.   StartTick := TimerTick;
  64.   while StartTick = TimerTick do {wait for end of TimerTick};
  65.   StartTick := TimerTick;
  66.   repeat
  67.     Inc(i);
  68.     if InSet(CSet,Ord(Buffer[i])) then Inc(Reps)
  69.                                   else Inc(Reps);
  70.   until StartTick <> TimerTick;
  71.   Normaliseer := Reps;
  72.  
  73.   i := 0;
  74.   Reps := 0;
  75.   StartTick := TimerTick;
  76.   while StartTick = TimerTick do {wait for end of TimerTick};
  77.   StartTick := TimerTick;
  78.   repeat
  79.     Inc(i);
  80.     if Buffer[i] in CSet then Inc(Reps)
  81.                          else Inc(Reps);
  82.   until StartTick <> TimerTick;
  83.   writeln('Bob Swart in: ',(100 * Normaliseer) div Reps:8);
  84.   writeln('Borland in:        100');
  85.   Normaliseer := Reps;
  86.  
  87.   i := 0;
  88.   Reps := 0;
  89.   StartTick := TimerTick;
  90.   while StartTick = TimerTick do {wait for end of TimerTick};
  91.   StartTick := TimerTick;
  92.   repeat
  93.     Inc(i);
  94.     C := Buffer[i];
  95.     if (C = 'b') or (C = 'o') or (C = 'l') or (C = 'e') or
  96.        (C = 's') or (C = 'i') or (C = 'a') or (C = 'n') then Inc(Reps)
  97.                                                         else Inc(Reps);
  98.   until StartTick <> TimerTick;
  99.   writeln('Borland if: ',(100 * Reps) div Normaliseer:10);
  100.  
  101.   i := 0;
  102.   Reps := 0;
  103.   StartTick := TimerTick;
  104.   while StartTick = TimerTick do {wait for end of TimerTick};
  105.   StartTick := TimerTick;
  106.   repeat
  107.     Inc(i);
  108.     C := Buffer[i];
  109.     case C of
  110.       'b','o','l','e','s','i','a','n': Inc(Reps);
  111.       else Inc(Reps);
  112.     end;
  113.   until StartTick <> TimerTick;
  114.   writeln('Borland case: ',(100 * Reps) div Normaliseer:8);
  115.  
  116.   i := 0;
  117.   Reps := 0;
  118.   StartTick := TimerTick;
  119.   while StartTick = TimerTick do {wait for end of TimerTick};
  120.   StartTick := TimerTick;
  121.   repeat
  122.     Inc(i);
  123.     if InSet25(CSet,Ord(Buffer[i])) then Inc(Reps)
  124.                                     else Inc(Reps);
  125.   until StartTick <> TimerTick;
  126.   writeln('Bob Swart 25: ',(100 * Reps) div Normaliseer:8)
  127. end.
  128.