如何统计一段程序的运行时间? 由于我的程序要统计执行时间,请问该如何完成,有现成的控件来实现类似的功能吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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; 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. 我觉得应该采用GetTickCount()函数,因为该函数只与CMOS时钟有关,而与Now无关。//以下是说明:var BeginTime,EndTime: Cardinal;BeginTime := GetTickCount();Run Application;EndTime := GetTickCount();Result := EndTime - BeginTime; 加个时钟(定时器):YXtime:Integer; //全局变量YXtime:=0; //初始化变量procedure TForm1.Timer1Timer(Sender: TObject);Var HourStr, Minstr : stringbegin YXtime:=YXtime + timer1.Interval div 60000; HourStr:=inttostr(YXtime div 60); Minstr:=inttostr(YXtime mod 60); Label1.Caption:=HourStr+' 时 '+MinStr+' 分';end; 两次GetTickCount之差可以得到准确的体统在这段时间内的运行时间,不过是系统的,不是你的程序。若想得到精确的程序运行时间在2000下可以用 getthreadtimes ,98下没有实现。这个函数可以得到具体线程的cpu时间,包括用户模式和内核模式。 救命!!! 有人用过midioutopen等midi的Api吗??请进 如何获取本机IP 300高分,求解TCP连接中的问题。 动态创建窗口 发红包喽。。。。。发红包喽。。。。。 存储过程问题!我实在没办法解决了! 谁开发过GOLF会员俱乐部管理系统或谁用过除远古系统以外的????? 关于TQuery 的问题 怎样得到控件的名字 请问如何判断INTERNET是否连通?(最好是一个function) 关于组件和插件的联系和差别
var
t1,t2:TTime;
begin
t1:=now;
sleep(1133); //或你程序
t2:=now;
Label1.Caption:=FormatDateTime('hh:mm:ss.zzz',t2-t1);//可得到1/1000秒end;
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.
var
BeginTime,EndTime: Cardinal;BeginTime := GetTickCount();Run Application;EndTime := GetTickCount();Result := EndTime - BeginTime;
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;
这个函数可以得到具体线程的cpu时间,包括用户模式和内核模式。