Delphi测试数据库连接时间


本文整理自网络,侵删。

 
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. 

相关阅读 >>

Delphi 根据文本高度确定richedit高度

Delphi监控指定进程防止被关闭

Delphi的流操作的语法

Delphi idftp 使用被动连接

Delphi 中使长循环有响应

Delphi tstringlist 保存txt文本文件最后一行不留空行

Delphi 根据字符串找到函数并执行

Delphi 动态修改显示器分辨率

Delphi 中流的使用通过内存流读取文件

Delphi txt日志log

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...