Delphi单元PAS代码:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MSSQL,
FireDAC.Phys.MSSQLDef, FireDAC.VCLUI.Wait, FireDAC.Comp.UI, Data.DB,
FireDAC.Comp.Client, Vcl.StdCtrls;
type
TForm1 = class(TForm)
FDConnection1: TFDConnection;
FDGUIxWaitCursor1: TFDGUIxWaitCursor;
grp1: TGroupBox;
edtServer: TEdit;
lbl1: TLabel;
edtUser_Name: TEdit;
lbl2: TLabel;
edtPassword: TEdit;
lbl3: TLabel;
grp2: TGroupBox;
edtCount: TEdit;
lbl4: TLabel;
btn1: TButton;
mmo1: TMemo;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
t1, t2, t3: Extended;
i, count: integer;
begin
FDConnection1.Close;
FDConnection1.Params.Values['Server'] := edtServer.Text;
FDConnection1.Params.Values['User_Name'] := edtUser_Name.Text;
FDConnection1.Params.Values['Password'] := edtPassword.Text;
t1 := GetTickCount;
count := StrToIntDef(edtCount.Text, 0);
for i := 0 to count - 1 do
begin
FDConnection1.Open();
FDConnection1.Close;
end;
t2 := GetTickCount;
t3 := (t2 - t1) / 1000;
mmo1.Lines.Add(format('测试次数:%d 次;耗时:%f 秒;平均每次:%f 秒;', [count, t3, t3 / count]
)); // 显示耗时
end;
end.