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二分查找算法(预排序数组的查找)

Delphi模仿“千千静听”滚动标题栏

android开发-px和dip以及sp的区别

Delphi 压缩带密码的access数据库的方法

Delphi的initialization和finalization

Delphi tnethttpclient演示

Delphi 隐藏进程的单元 unit hideprocess.pas

Delphi 获取android id 号

Delphixe8中获取apk的签名信息

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



打赏

取消

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

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

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

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

评论

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