由于我的程序要统计执行时间,请问该如何完成,有现成的控件来实现类似的功能吗?

解决方案 »

  1.   

    procedure TForm1.Button3Click(Sender: TObject);
    var
      t1,t2:TTime;
    begin
      t1:=now;
      sleep(1133); //或你程序
      t2:=now;
      Label1.Caption:=FormatDateTime('hh:mm:ss.zzz',t2-t1);//可得到1/1000秒end;
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls;type
      TForm1 = class(TForm)
        Label1: TLabel;
        Timer1: TTimer;
        procedure FormCreate(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      time1,time2:TTime;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
       time1:=now;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      time2:=now;
      Label1.Caption:=FormatDateTime('hh:mm:ss.zzz',time2-time1);
    end;end.
      

  3.   

    我觉得应该采用GetTickCount()函数,因为该函数只与CMOS时钟有关,而与Now无关。//以下是说明:
    var
      BeginTime,EndTime: Cardinal;BeginTime := GetTickCount();Run Application;EndTime := GetTickCount();Result := EndTime - BeginTime;
      

  4.   

    加个时钟(定时器):
    YXtime:Integer;   //全局变量
    YXtime:=0; //初始化变量
    procedure TForm1.Timer1Timer(Sender: TObject);
    Var
       HourStr, Minstr : string
    begin
         YXtime:=YXtime + timer1.Interval div 60000;
         HourStr:=inttostr(YXtime div 60);
         Minstr:=inttostr(YXtime mod 60);                    
         Label1.Caption:=HourStr+' 时 '+MinStr+' 分';
    end;
      

  5.   

    两次GetTickCount之差可以得到准确的体统在这段时间内的运行时间,不过是系统的,不是你的程序。若想得到精确的程序运行时间在2000下可以用 getthreadtimes ,98下没有实现。
    这个函数可以得到具体线程的cpu时间,包括用户模式和内核模式。