home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol8n14.zip / SLOWFAST.PAS < prev   
Pascal/Delphi Source File  |  1989-06-25  |  2KB  |  65 lines

  1.  
  2.  
  3.  
  4. {$A-} {Delete this line for TP4}
  5. PROGRAM SlowFast;
  6. (* This program is used to demonstrate how
  7.    a program can be slowed with data
  8.    misalignment on a 16-bit computer.*)
  9. USES Dos;
  10. CONST
  11.   oddeven : ARRAY[Boolean] of String[4] =
  12.           ('EVEN','ODD ');
  13. VAR
  14.   Start, Elapsed : LongInt;
  15.   i, EmptyLoop : LongInt;
  16.   b : byte;
  17.   j : LongInt;
  18.  
  19.   FUNCTION time100ths : LongInt;
  20.   VAR H,M,S,F : Word;
  21.   BEGIN
  22.     GetTime(H,M,S,F);
  23.     Time100ths := (((((LongInt(H)*60) + M) * 60) + S) * 100) + F;
  24.   END;
  25.  
  26.   {$IFDEF VER40}
  27.   PROCEDURE Neutral;
  28.   BEGIN END;
  29.  
  30.   PROCEDURE Slow;
  31.   VAR b : Byte;
  32.   BEGIN  Neutral; END;
  33.  
  34.   PROCEDURE Fast;
  35.   BEGIN  Neutral;  END;
  36.   {$ENDIF}
  37.  
  38. BEGIN
  39.   WriteLn('Offset of i, ',ofs(i),' is ',oddeven[odd(ofs(i))]);
  40.   WriteLn('Offset of j, ',ofs(j),' is ',oddeven[odd(ofs(j))]);
  41.   Start := Time100ths;
  42.   FOR i := 1 TO 1000000 DO {nothing} ;
  43.   Elapsed := Time100ths-Start;
  44.   EmptyLoop := Elapsed;
  45.   WriteLn('Time using i: ', Elapsed DIV 100,'.', Elapsed MOD 100);
  46.   Start := Time100ths;
  47.   FOR j := 1 TO 1000000 DO {nothing} ;
  48.   Elapsed := Time100ths-Start;
  49.   WriteLn('Time using j: ', Elapsed DIV 100,'.', Elapsed MOD 100);
  50.   {$IFDEF VER40}
  51.   Start := time100ths;
  52.   FOR i := 1 to 1000000 DO fast;
  53.   Elapsed := time100ths - Start - EmptyLoop;
  54.   WriteLn('Time using fast: ', Elapsed DIV 100,'.', Elapsed MOD 100);
  55.   Start := time100ths;
  56.   FOR i := 1 to 1000000 DO slow;
  57.   Elapsed := time100ths - Start - EmptyLoop;
  58.   WriteLn('Time using slow: ', Elapsed DIV 100,'.', Elapsed MOD 100);
  59.   {$ELSE}
  60.   WriteLn('No stack test -- TP5 aligns the stack even with {$A-}');
  61.   {$ENDIF}
  62. END.
  63.  
  64.  
  65.