home *** CD-ROM | disk | FTP | other *** search
/ Mega CD-ROM 1 / megacd_rom_1.zip / megacd_rom_1 / MAGAZINE / INSIDE_T / ITPJUN90.ZIP / TEST.PAS < prev    next >
Pascal/Delphi Source File  |  1990-05-10  |  2KB  |  61 lines

  1. PROGRAM Test;
  2. { TEST - Test the timer library.  This Program
  3.   times how long it takes to obtain the current
  4.   time with the two methods described in the
  5.   article.                                      }
  6.  
  7. USES Crt,Dos,Timer;
  8. VAR
  9.    EmptyLoopTime : Real;
  10.    Q             : Longint;
  11.  
  12. PROCEDURE PrintResults(A,B: Longint;S1,S2:String);
  13. {PrintResults procedure displays accurate message
  14.  only if you run the test loop 1,000,000 times}
  15. VAR
  16.    tInterval : Real;
  17. BEGIN
  18.    WriteLn(tFormat(A,B),
  19.     ' seconds FOR 1,000,000 invocations OF ',S1);
  20.    tInterval := tDiff(A,B) - EmptyLoopTime;
  21.     {Adjust display for midnight crossover
  22.       60*60*24 is the number of seconds in a day}
  23.    IF tInterval < 0 THEN
  24.          tInterval := tInterval + (60*60*24);
  25.    WriteLn('This equals ',tInterval:8:6,
  26.            ' µs per ',S2);
  27.    WriteLn
  28. END;
  29.  
  30. VAR
  31.    T1,T2,I,J : Longint;
  32.    Hour, Minute, Second, Sec100 : Word;
  33. BEGIN
  34.    ClrScr;
  35.    T1 :=tStart;
  36.    FOR I:= 1 TO 1000000 DO;
  37.    T2 := tGet;
  38.    PrintResults(T1,T2,'*** Empty Loop ***',
  39.                 'Loop.');
  40.    EmptyLoopTime := tDiff(T1,T2);
  41.    {How long does it take to call GetTime?}
  42.    T1 := tStart;
  43.    FOR I:= 1 TO 1000000 DO
  44.      Dos.GetTime(Hour, Minute, Second, Sec100);
  45.    T2 := tGet;
  46.    PrintResults(T1,T2,'*** Dos.GetTime() ***',
  47.                 'call.');
  48.    T1 := tStart;
  49.    FOR I:= 1 TO 1000000 DO
  50.       Timer.GetTime(Hour,Minute,Second,Sec100);
  51.    T2 := tGet;
  52.    PrintResults(T1,T2,'*** Timer.GetTime() ***',
  53.                 'call.');
  54.    T1 := tStart;
  55.    FOR I:= 1 TO 1000000 DO
  56.        Q := tGet;
  57.    T2 := tGet;
  58.    PrintResults(T1,T2,'*** tGet() ***','call.');
  59.    WriteLn('Tests Completed')
  60. END.
  61.