home *** CD-ROM | disk | FTP | other *** search
/ AMIGA PD 1 / AMIGA-PD-1.iso / Programme_zum_Heft / Programmieren / Kurztests / PascalPCQ / Examples / TimeProg.p < prev    next >
Text File  |  1991-02-08  |  1KB  |  61 lines

  1. Program TimeProg;
  2.  
  3. {
  4.  
  5.     TimeProg ProgramName
  6.  
  7.     Accurately times the execution of ProgramName.
  8.  
  9.     A very simple example of using the timer.device and its
  10.     support functions, as well as using the RunProgram routines.
  11.     Note that this program will not work with programs that require
  12.     the CLI, nor will it work for the standard BCPL programs at all.
  13. }
  14.  
  15. {$I "Include:Devices/Timer.i"}
  16. {$I "Include:Utils/TimerUtils.i"}
  17. {$I "Include:Utils/RunProgram.i"}
  18. {$I "Include:Libraries/DOSExtens.i"}
  19. {$I "Include:Utils/StringLib.i"}
  20. {$I "Include:Utils/Parameters.i"}
  21.  
  22.  
  23. var
  24.     T : TimeRequestPtr;
  25.     StartTime,
  26.     EndTime : TimeVal;
  27.  
  28.     ProgramName : String;
  29.     ProgPtr    : BPTR;
  30.  
  31. begin
  32.     ProgramName := AllocString(256);
  33.     GetParam(1, ProgramName);
  34.     if ProgramName^ = '\0' then begin
  35.     Writeln('Usage: TimeProg Progname');
  36.     Exit(10);
  37.     end;
  38.  
  39.     ProgPtr := LoadSeg(ProgramName);
  40.     if ProgPtr = Nil then begin
  41.     Writeln('Could not load ', ProgramName);
  42.     Exit(10);
  43.     end;
  44.  
  45.     T := CreateTimer;
  46.     
  47.     if T <> Nil then begin
  48.     GetSysTime(T, StartTime);
  49.     if RunSegment("TimeProg.sub", ProgPtr, 8000) then begin
  50.         GetSysTime(T, EndTime);
  51.         SubTime(EndTime, StartTime);
  52.         Writeln('Difference: ', Float(EndTime.tv_Secs and $FFFF) +
  53.                 Float(EndTime.tv_Micro) / 1000000.0:0:8);
  54.     end else
  55.         Writeln('Could not run the program');
  56.     DeleteTimer(T);
  57.     UnloadSeg(ProgPtr);
  58.     end else
  59.     Writeln('Could not open timer.');
  60. end.
  61.