如何统计一段程序的运行时间?

sufangzhong 2003-05-09 12:25:54
由于我的程序要统计执行时间,请问该如何完成,有现成的控件来实现类似的功能吗?
...全文
29 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yansea 2003-05-09
  • 打赏
  • 举报
回复
两次GetTickCount之差可以得到准确的体统在这段时间内的运行时间,不过是系统的,不是你的程序。若想得到精确的程序运行时间在2000下可以用 getthreadtimes ,98下没有实现。
这个函数可以得到具体线程的cpu时间,包括用户模式和内核模式。
NamasAmitabha 2003-05-09
  • 打赏
  • 举报
回复
加个时钟(定时器):
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;
myyanghua 2003-05-09
  • 打赏
  • 举报
回复
我觉得应该采用GetTickCount()函数,因为该函数只与CMOS时钟有关,而与Now无关。

//以下是说明:
var
BeginTime,EndTime: Cardinal;

BeginTime := GetTickCount();

Run Application;

EndTime := GetTickCount();

Result := EndTime - BeginTime;
jackie168 2003-05-09
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
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.
madyak 2003-05-09
  • 打赏
  • 举报
回复
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;

828

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧