home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / TIMING.SWG / 0004_Re: CPU-time.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  3.0 KB  |  118 lines

  1. {
  2. Mattias Hansson (d92mh@efd.lth.se) wrote:
  3. : I wonder if there is any way to check how fast a program is executing.
  4. : The program should look like this
  5.  
  6. : ...
  7. : starttime:="CPU-time"
  8. : ... doing something ...
  9. : stoptime:="CPU-time"
  10. : execution-time:=stoptime-starttime
  11. : ...
  12.  
  13. : IS IT POSSIBLE IN PASCAL ?
  14.  
  15. I mad somethink LONG LONG ago, so it may be wrong, slow buggy etc.. 
  16.  
  17. -- CUT HERE ---
  18. }
  19. unit DURATION;
  20.  
  21. interface
  22.  
  23. uses dos;
  24.  
  25. var  starttime,endtime,dauer : STRING[22];
  26.  
  27. procedure startzeit;
  28. {r da, um die StartZeit festzulegen }
  29. procedure endzeit;
  30. {r da, um die EndZeit festzulegen }
  31. procedure zeitformat;
  32. { Berechnet die Dauer, und Formatiert die Strings }
  33.  
  34. implementation
  35.  
  36. var hour,minute,second,thousend     : integer;
  37.     hour1,minute1,second1,thousend1,
  38.     hour2,minute2,second2,thousend2 : word;
  39.  
  40. procedure startzeit;
  41. begin
  42.   GetTime(hour1,minute1,second1,thousend1);
  43. end;
  44.  
  45. procedure endzeit;
  46. begin
  47.   GetTime(hour2,minute2,second2,thousend2);
  48. end;
  49.  
  50. PROCEDURE zeitformat;
  51. VAR strngs : STRING[2];
  52. BEGIN
  53.   starttime:='';       { Etwas kompliziert zu lesen, mir fiel aber }
  54.   endtime :='';        { nichts anderes ein...                     }
  55.   dauer   :='';
  56.   Str(hour1,strngs);
  57.   IF Length(strngs)<2 THEN Insert('0',strngs,1);
  58.   starttime:=starttime+strngs+':';
  59.   Str(minute1,strngs);
  60.   IF Length(strngs)<2 THEN Insert('0',strngs,1);
  61.   starttime:=starttime+strngs+':';
  62.   Str(second1,strngs);
  63.   IF Length(strngs)<2 THEN Insert('0',strngs,1);
  64.   starttime:=starttime+strngs+'.';
  65.   Str(thousend1,strngs);
  66.   IF Length(strngs)<2 THEN Insert('0',strngs,1);
  67.   starttime:=starttime+strngs;
  68.   Str(hour2,strngs);
  69.   IF Length(strngs)<2 THEN Insert('0',strngs,1);
  70.   endtime:=endtime+strngs+':';
  71.   Str(minute2,strngs);
  72.   IF Length(strngs)<2 THEN Insert('0',strngs,1);
  73.   endtime:=endtime+strngs+':';
  74.   Str(second2,strngs);
  75.   IF Length(strngs)<2 THEN Insert('0',strngs,1);
  76.   endtime:=endtime+strngs+'.';
  77.   Str(thousend2,strngs);
  78.   IF Length(strngs)<2 THEN Insert('0',strngs,1);
  79.   endtime:=endtime+strngs;
  80.   IF hour1>hour2 THEN
  81.     BEGIN
  82.       hour:=24+hour2-hour1;
  83.     END
  84.   ELSE hour:=hour2-hour1;
  85.   IF minute1>minute2 THEN
  86.     BEGIN
  87.       minute:=60+minute2-minute1;
  88.       hour:=hour-1;
  89.     END
  90.   ELSE minute:=minute2-minute1;
  91.   IF second1>second2 THEN
  92.     BEGIN
  93.       second:=60+second2-second1;
  94.       minute:=minute-1;
  95.     END
  96.   ELSE second:=second2-second1;
  97.   IF thousend1>thousend2 THEN
  98.     BEGIN
  99.       thousend:=100+thousend2-thousend1;
  100.       second:=second-1;
  101.     END
  102.   ELSE thousend:=thousend2-thousend1;
  103.   Str(hour,strngs);
  104.   IF Length(strngs)<2 THEN Insert('0',strngs,1);
  105.   dauer:=dauer+strngs+':';
  106.   Str(minute,strngs);
  107.   IF Length(strngs)<2 THEN Insert('0',strngs,1);
  108.   dauer:=dauer+strngs+':';
  109.   Str(second,strngs);
  110.   IF Length(strngs)<2 THEN Insert('0',strngs,1);
  111.   dauer:=dauer+strngs+'.';
  112.   Str(thousend,strngs);
  113.   IF Length(strngs)<2 THEN Insert('0',strngs,1);
  114.   dauer:=dauer+strngs;
  115. END;
  116.  
  117. end.
  118.