home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / turbopas / bonus507.arc / TPTIMER.ARC / BENCH.PAS next >
Pascal/Delphi Source File  |  1988-10-03  |  2KB  |  70 lines

  1. {$S-,R-,I-,V-,B-}
  2.  
  3. {*********************************************************}
  4. {*                    BENCH.PAS 1.00                     *}
  5. {*                by TurboPower Software                 *}
  6. {*********************************************************}
  7.  
  8. program Bench;
  9.   {-Benchmark a program}
  10.  
  11. uses
  12.   tptimer, tpstring, tpdos;
  13.  
  14. (*
  15.   BENCH is a simple utility for benchmarking compiled programs. It uses
  16.   the ExecDos procedure in the TPDOS unit to EXEC the program, and the
  17.   TPTIMER unit to measure its execution time.
  18.  
  19.   For example, let's say that you wanted to compare the performance of
  20.   MASM against that of Turbo Assembler, using TPTSR.ASM as a test case.
  21.   You would enter the following commands at the DOS prompt:
  22.  
  23.      BENCH MASM TPTSR;
  24.      BENCH TASM TPTSR
  25.  
  26.   For best results, especially in comparisons, the program(s) being
  27.   benchmarked should be on a RAM disk, in order to minimize the amount of time
  28.   spent by DOS in loading the program.
  29. *)
  30.  
  31. type
  32.   StringPtr = ^string;
  33. var
  34.   CmdLine : String;
  35.   Code : Integer;
  36.   Start, Stop : LongInt;
  37.  
  38. begin
  39.   WriteLn('BENCH. Utility for benchmarking programs.');
  40.   if ParamCount = 0 then begin
  41.     WriteLn('Usage: BENCH progname [params]');
  42.     Halt;
  43.   end;
  44.  
  45.   {get a copy of the command line}
  46.   CmdLine := TrimLead(StringPtr(Ptr(PrefixSeg, $80))^);
  47.  
  48.   {time the execution of the program}
  49.   Start := ReadTimer;
  50.   Code := ExecDos(CmdLine, True, nil);
  51.   Stop := ReadTimer;
  52.  
  53.   {check the return code}
  54.   case Code of
  55.     0 : {Success} ;
  56.    -1 : WriteLn('Insufficient memory to store free list');
  57.    -2 : WriteLn('DOS setblock error before EXEC call');
  58.    -3 : WriteLn('DOS setblock error after EXEC call');
  59.    -4 : WriteLn('Insufficient memory to run DOS command');
  60.    else WriteLn('DOS reports error code of ', Code);
  61.   end;
  62.  
  63.   {halt in case of error}
  64.   if Code <> 0 then
  65.     Halt(1);
  66.  
  67.   {report elapsed time}
  68.   WriteLn('Elapsed time: ', ElapsedTime(Start, Stop)/1000.0:0:2, ' seconds');
  69. end.
  70.