home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / h / htmix20.zip / MISC.ZIP / TIM.PAS < prev   
Pascal/Delphi Source File  |  1992-07-13  |  4KB  |  126 lines

  1. program Timer;
  2. {┌──────────────────────────────── INFO ────────────────────────────────────┐}
  3. {│ File    : TIM.PAS                                                        │}
  4. {│ Author  : Harald Thunem                                                  │}
  5. {│ Purpose : Find time used in programs/commands.                           │}
  6. {│ Updated : July 10 1992                                                   │}
  7. {└──────────────────────────────────────────────────────────────────────────┘}
  8.  
  9. {────────────────────────── Compiler directives ─────────────────────────────}
  10. {$A+   Word align data                                                       }
  11. {$B-   Short-circuit Boolean expression evaluation                           }
  12. {$E-   Disable linking with 8087-emulating run-time library                  }
  13. {$G+   Enable 80286 code generation                                          }
  14. {$R-   Disable generation of range-checking code                             }
  15. {$S-   Disable generation of stack-overflow checking code                    }
  16. {$V-   String variable checking                                              }
  17. {$X-   Disable Turbo Pascal's extended syntax                                }
  18. {$N+   80x87 code generation                                                 }
  19. {$D-   Disable generation of debug information                               }
  20. {────────────────────────────────────────────────────────────────────────────}
  21. {$M $4000,0,0}  { Memory specifications }
  22.  
  23. uses Dos;
  24.  
  25. var  Command     : string;
  26.      StartHour,
  27.      StartMinute,
  28.      StartSecond,
  29.      StartSec100,
  30.      StopHour,
  31.      StopMinute,
  32.      StopSecond,
  33.      StopSec100  : word;
  34.      UsedTime,
  35.      StartTime,
  36.      StopTime    : extended;
  37.  
  38.  
  39. procedure ShowOptions;
  40. begin
  41.   WriteLn('Program : TIM  --  Program Execution Timer 2.0');
  42.   WriteLn('Author  : Harald Thunem');
  43.   WriteLn('Purpose : Find time used in program/command');
  44.   WriteLn('Updated : July 10 1992');
  45.   WriteLn;
  46.   WriteLn('Usage   : TIM Command');
  47.   WriteLn;
  48.   WriteLn('          Ex:  TIM copy *.pas a:\');
  49.   Halt(1);
  50. end;
  51.  
  52.  
  53. function UpcaseStr(s: string): string;
  54. var i: byte;
  55. begin
  56.   for i := 1 to Length(s) do
  57.     s[i] := Upcase(s[i]);
  58.   UpcaseStr := s;
  59. end;
  60.  
  61.  
  62. procedure GetCommand(var Command: string);
  63. var i: byte;
  64. begin
  65.   Command := '';
  66.   if ParamCount=0 then ShowOptions;
  67.   for i := 1 to ParamCount do
  68.   Command := Command + UpcaseStr(ParamStr(i)) + ' ';
  69. end;
  70.  
  71.  
  72. {$F+}procedure ExecuteCommand(Command: string);{$F-}
  73. begin
  74.   SwapVectors;
  75.   Exec(GetEnv('COMSPEC'),'/C '+Command);
  76.   SwapVectors;
  77.   if DosError<>0 then
  78.     WriteLn('Could not execute ',Command,'. Dos error # ',DosError);
  79. end;
  80.  
  81.  
  82. function GetLongTime(H,M,S,S100: word): extended;
  83. begin
  84.   GetLongTime := (0.01*S100) + S + 60*M + 3600*H;
  85. end;
  86.  
  87.  
  88. function TimeStr(Time: extended): string;
  89. var s1,s2: string;
  90.     v    : extended;
  91. begin
  92.   v := Trunc(Time / 3600);
  93.   Time := Time - v*3600;
  94.   Str(v:1:0,s1);
  95.   if Length(s1)=1 then s1 := '0'+s1;
  96.   v := Trunc(Time / 60);
  97.   Time := Time - v*60;
  98.   Str(v:1:0,s2);
  99.   if Length(s2)=1 then s2 := '0'+s2;
  100.   s1 := s1 + ':' + s2;
  101.   v := Time;
  102.   Str(v:1:2,s2);
  103.   if Length(s2)=4 then s2 := '0'+s2;
  104.   s1 := s1 + ':' + s2;
  105.   TimeStr := s1;
  106. end;
  107.  
  108.  
  109. begin
  110.   GetCommand(Command);
  111.   GetTime(StartHour,StartMinute,StartSecond,StartSec100);
  112.   ExecuteCommand(Command);
  113.   GetTime(StopHour,StopMinute,StopSecond,StopSec100);
  114.   StartTime := GetLongTime(StartHour,StartMinute,StartSecond,StartSec100);
  115.   StopTime := GetLongTime(StopHour,StopMinute,StopSecond,StopSec100);
  116.   UsedTime := StopTime-StartTime;
  117.   WriteLn;
  118.   WriteLn('TIMER 2.0                                                    Written by H.Thunem');
  119.   WriteLn('────────────────────────────────────────────────────────────────────────────────');
  120.   WriteLn('Command    : ',Command);
  121.   WriteLn('Start time : ',TimeStr(StartTime));
  122.   WriteLn('Stop time  : ',TimeStr(StopTime));
  123.   WriteLn('Used time  : ',TimeStr(UsedTime));
  124.   WriteLn('────────────────────────────────────────────────────────────────────────────────');
  125. end.
  126.