C
cwf2002cwf
Unregistered / Unconfirmed
GUEST, unregistred user!
这是一个计算网页 http 响应时间的程序,如下:
=====================================================================
unit idhttpA;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure myWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
timestamp:dword;
myhttp:Tidhttp;
isOK:boolean;//用来截获respones 200信息,并屏蔽后面继续触发的该事件的开关;
implementation
{$R *.dfm}
procedure TForm1.myWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
if ((myhttp.ResponseCode=200) and (isOk=false)) then
begin
isOK:=true;
timestamp:=GetTickCount-timestamp;
showmessage(inttostr(timestamp));
end;
showmessage(inttostr(myhttp.ResponseCode));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
myhttp:=Tidhttp.Create(self);
myhttp.OnWork:=myWork;
isOk:=false;
try
timestamp:=GetTickCount;
myhttp.Get('http://www.sina.com.cn');
except
on E:EIdHTTPProtocolException do
//showmessage('the error');
end;
myhttp.Free;
end;
end.
=======================The End ==============================================
我在delphi中run时, 第一次点击 button1时, 比如显示 218ms, 那么继续点第二次,第三次...
数值就会在 80~100之间,反正在数量级别上是第一次的一半,屡试不爽。
怎么样才能得到每次点击的数值是接近的呢?请高手指定。
PS:开始我还以为是因为Idhttp 的socket连接还维持着,所以第一次点击以后,接下来都会快点。
但是现在我已经在程序中把Idhttp free掉了呀。
=====================================================================
unit idhttpA;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure myWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
timestamp:dword;
myhttp:Tidhttp;
isOK:boolean;//用来截获respones 200信息,并屏蔽后面继续触发的该事件的开关;
implementation
{$R *.dfm}
procedure TForm1.myWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
if ((myhttp.ResponseCode=200) and (isOk=false)) then
begin
isOK:=true;
timestamp:=GetTickCount-timestamp;
showmessage(inttostr(timestamp));
end;
showmessage(inttostr(myhttp.ResponseCode));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
myhttp:=Tidhttp.Create(self);
myhttp.OnWork:=myWork;
isOk:=false;
try
timestamp:=GetTickCount;
myhttp.Get('http://www.sina.com.cn');
except
on E:EIdHTTPProtocolException do
//showmessage('the error');
end;
myhttp.Free;
end;
end.
=======================The End ==============================================
我在delphi中run时, 第一次点击 button1时, 比如显示 218ms, 那么继续点第二次,第三次...
数值就会在 80~100之间,反正在数量级别上是第一次的一半,屡试不爽。
怎么样才能得到每次点击的数值是接近的呢?请高手指定。
PS:开始我还以为是因为Idhttp 的socket连接还维持着,所以第一次点击以后,接下来都会快点。
但是现在我已经在程序中把Idhttp free掉了呀。