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 如何取得键盘每个键

Delphi中判断操作系统是否是windows7

Delphi 清除ie缓存 internet临时文件 cookie 历史记录 表单记录 上网密码

Delphi system.messaging.pas例子

Delphi 搭配hotkeyedit控件来解决问题

Delphi得到系统目录的几个方法

Delphi memo1 统计行 列

Delphi文件是否正在使用

Delphi twebbrowser静音

Delphi xe 中的字符串生成哈希值(md5 / sha-1 / jenkins)

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



打赏

取消

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

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

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

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

评论

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