home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / CLOCKSTP.ZIP / TIMER.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-23  |  2.5 KB  |  89 lines

  1. {$M $2000,0,0}
  2. PROGRAM Timer;
  3.  
  4.  {This program uses the Clocks UNIT to time any DOS command executed
  5.   from native DOS or via a BAT file.
  6.  
  7.   (C) Copyright 1989, Earl F. Glynn, Overland Park, KS.  Compuserve 73257,3527
  8.  
  9.   Use
  10.  
  11.        TIMER dos command
  12.  
  13.   to time any DOS comamand.  Output is always displayed on the screen.
  14.   A timer log file entry will be written to the file specified by
  15.   the DOS TIMER environment variable.  Use
  16.  
  17.        SET TIMER=filename.ext to
  18.  
  19.   to specify this environment variable.  If no TIMER environment
  20.   variable exists, output will only be made to the screen.}
  21.  
  22.   USES
  23.     Clocks,
  24.     DOS;  {PathStr,GetEnv}
  25.  
  26.   VAR
  27.     clk1     :  Clock;
  28.     clk2     :  Clock;
  29.     command  :  STRING;
  30.     error    :  WORD;
  31.     i        :  WORD;
  32.     log      :  TEXT;
  33.     logfile  :  PathStr;
  34.     seconds1 :  REAL;
  35.     seconds2 :  REAL;
  36.     WriteFlag:  BOOLEAN;
  37.  
  38. BEGIN
  39.   logfile := GetEnv('TIMER');
  40.   WriteFlag := (LENGTH(logfile) > 0);
  41.   IF   ParamCount = 0
  42.   THEN command := '*'                     {Use '*' for comments.}
  43.   ELSE BEGIN
  44.     command := '';
  45.     FOR  i := 1 TO ParamCount DO
  46.       command := command + ParamStr(i) + ' ';
  47.   END;
  48.   IF   COPY(command,1,1) <> '*'
  49.   THEN BEGIN
  50.     SwapVectors;
  51.     clk1.Start(DOSClock);
  52.     clk2.Start(CMOSClock);
  53.     EXEC (GetEnv('COMSPEC'),'/C '+command);
  54.     seconds1 := clk1.Elapsed;
  55.     seconds2 := clk2.Elapsed;
  56.     SwapVectors;
  57.   END;
  58.   IF   WriteFlag
  59.   THEN BEGIN
  60.     ASSIGN (log,logfile);
  61.     {$I-} APPEND (log); {$I+}
  62.     error := IORESULT;
  63.     IF   error <> 0          {File does not exist.  Create it.}
  64.     THEN BEGIN
  65.       {$I-} REWRITE (log); {$I+}
  66.       error := IORESULT;
  67.       IF   error <> 0
  68.       THEN BEGIN
  69.         WRITELN ('Cannot APPEND or REWRITE Timer file ''',logfile,'''.');
  70.         HALT
  71.       END;
  72.       WRITELN (log,'   Start (CMOS)      Elapsed Time');
  73.       WRITELN (log,'  Date     Time     CMOS     DOS           Command');
  74.       WRITELN (log,'-------- --------  ------ ---------  -------------------');
  75.     END;
  76.     IF   COPY(command,1,1) = '*'
  77.     THEN WRITELN (log,' ':37,COPY(command,2,LENGTH(command)-1))
  78.     ELSE WRITELN (log,clk2.Date('U'),' ',clk2.Time('N'),
  79.         seconds2:8:0,seconds1:10:2,'  ',command);
  80.     CLOSE (log)
  81.   END;
  82.   IF   COPY(command,1,1) <> '*'
  83.   THEN BEGIN
  84.     WRITELN (command);       {repeat command in case not on screen now}
  85.     WRITELN ('Start:  ',clk2.Date('U'),' ',clk2.Time(''),'  Elapsed:  ',
  86.       seconds2:6:0,' (CMOS) ',seconds1:8:2,' (DOS) second(s)');
  87.   END
  88. END {Timer}.
  89.