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 清空某个form的控件内容,用tag来判断

Delphi 线程同步(线程安全)

Delphi中怎样得到系统当前“输入法”名称?

Delphi 查询进程名进程id/进程路径 父进程/子进程

Delphi xe(indy10)tidbytes转ansistring的实现

Delphi package

Delphi-dbgrid取得所有表中的值

Delphi无dll穿墙下载者

Delphi 创建快捷方式的单元文件

Delphi 安卓app的http访问权限

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



打赏

取消

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

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

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

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

评论

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