Integer GUID和Comb做主键的效率测试(Delphi+access)(二)

看一下我们的表格构:

 

 

 

 TInteger表是用自动加1字段做为主键(PInt)

TGuid表是用GUID做为主键(PGUID)

PComb表是用Comb做为主键(PComb)

PComb2表是用改过后的Comb做为主键(PComb,第四种情况)

在这四表中还有一列,NInt,用于插入一个数值,随机的,没有什么实际的意义

 

 

 

 

 

下面先看一下我们的测试界面:

 

 

 

 

 

插入数据是指在数据库的四个表中插入指定条目的数据.

Count(*)是在四个表中用select cocunt(*) as rc from table做统计查询

Count是在四个表中用select cocunt(主键) as rc from table做统计查询

 

 

 

 

 

Label3,Label5,Label7,Label9分别是四个表所运行的时间.

 

 

 

 

 

下面是测试程序:

 

 

 

 

 

unit Unit1;

 

 

 

 

 

interface

 

 

 

 

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls,Activex,SSystemUnit, ADODB, DB;

 

 

 

 

 

type

  TForm1 = class(TForm)

    ADOConnection1: TADOConnection;

    ADOCommand1: TADOCommand;

    Edit1: TEdit;

    Button1: TButton;

    Label1: TLabel;

    Label2: TLabel;

    Label3: TLabel;

    Label4: TLabel;

    Label5: TLabel;

    Label6: TLabel;

    Label7: TLabel;

    Button2: TButton;

    Button3: TButton;

    Label8: TLabel;

    Label9: TLabel;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

  private

    { Private declarations }

    procedure InsertComb(cc : integer);

    procedure InsertComb2(cc : integer);

    procedure InsertGuid(cc : integer);

    procedure insertInt(cc : integer);

  public

    { Public declarations }

  end;

 

 

 

 

 

var

  Form1: TForm1;

 

 

 

 

 

implementation

 

 

 

 

 

{$R *.dfm}

 

 

 

 

 

procedure TForm1.Button1Click(Sender: TObject);

var

 TotalTime : Cardinal;

 cc : integer;

begin

cc:= strtoint(Edit1.Text);

TotalTime := GetTickCount;

insertInt(cc);

TotalTime := GetTickCount - TotalTime;

Label3.Caption := inttostr(TotalTime);

 

 

 

 

 

TotalTime := GetTickCount;

InsertGuid(cc);

TotalTime := GetTickCount - TotalTime;

Label5.Caption := inttostr(TotalTime);

 

 

 

 

 

TotalTime := GetTickCount;

InsertComb(cc);

TotalTime := GetTickCount - TotalTime;

Label7.Caption := inttostr(TotalTime);

 

 

 

 

 

TotalTime := GetTickCount;

InsertComb2(cc);

TotalTime := GetTickCount - TotalTime;

Label9.Caption := inttostr(TotalTime);

end;

 

 

 

 

 

procedure TForm1.InsertComb(cc : integer);

var

  i : integer;

begin

  ADOCommand1.CommandText :='Insert into TComb(PComb,NInt) values(:PComb,:NInt)';

  ADOCommand1.Prepared := true;

  For i:= 0 to cc-1 do

  begin

     ADOCommand1.Parameters[0].Value := SSystem.GetGuidString(SSystem.GetCombGUID(),'','','');

     ADOCommand1.Parameters[1].Value := i/7;

     ADOCommand1.Execute;

  end;

 

 

 

 

 

end;

 

 

 

 

 

procedure TForm1.InsertComb2(cc: integer);

var

  i : integer;

  //combStr : string;

begin

  ADOCommand1.CommandText :='Insert into TComb2(PComb,NInt) values(:PComb,:NInt)';

  ADOCommand1.Prepared := true;

  For i:= 0 to cc-1 do

  begin

     //combStr :=

     //combstr := copy(combstr,21,32)+copy(combstr,1,20);

     ADOCommand1.Parameters[0].Value := SSystem.GetGuidString2(SSystem.GetCombGUID(),'','','');;

     ADOCommand1.Parameters[1].Value := i/7;

     ADOCommand1.Execute;

  end;

 

 

 

 

 

end;

 

 

 

 

 

procedure TForm1.InsertGuid(cc : integer);

var

  i : integer;

  guid : TGUID;

begin

  ADOCommand1.CommandText :='Insert into TGuid(PGuid,NInt) values(:PGuid,:NInt)';

  ADOCommand1.Prepared := true;

  For i:= 0 to cc-1 do

  begin

     CoCreateGUID(guid);

     ADOCommand1.Parameters[0].Value := SSystem.GetGuidString(guid,'','','');

     ADOCommand1.Parameters[1].Value := i/7;

     ADOCommand1.Execute;

  end;

 

 

 

 

 

end;

 

 

 

 

 

procedure TForm1.insertInt(cc : integer);

var

  i : integer;

begin

  ADOCommand1.CommandText :='Insert into TInteger(NInt) values(:NInt)';

  ADOCommand1.Prepared := true;

  For i:= 0 to cc-1 do

  begin

     ADOCommand1.Parameters[0].Value := i/7;

     ADOCommand1.Execute;

  end;

 

 

 

 

 

end;

 

 

 

 

 

procedure TForm1.Button2Click(Sender: TObject);

var

 TotalTime : Cardinal;

begin

TotalTime := GetTickCount;

ADOCommand1.CommandText :='select count(*) as ttc from TInteger';

ADOCommand1.Execute;

TotalTime := GetTickCount - TotalTime;

Label3.Caption := inttostr(TotalTime);

 

 

 

 

 

TotalTime := GetTickCount;

ADOCommand1.CommandText :='select count(*) as ttc from TGuid';

ADOCommand1.Execute;

TotalTime := GetTickCount - TotalTime;

Label5.Caption := inttostr(TotalTime);

 

 

 

 

 

TotalTime := GetTickCount;

ADOCommand1.CommandText :='select count(*) as ttc from Tcomb';

ADOCommand1.Execute;

TotalTime := GetTickCount - TotalTime;

Label7.Caption := inttostr(TotalTime);

 

 

 

 

 

TotalTime := GetTickCount;

ADOCommand1.CommandText :='select count(*) as ttc from Tcomb2';

ADOCommand1.Execute;

TotalTime := GetTickCount - TotalTime;

Label9.Caption := inttostr(TotalTime);

end;

 

 

 

 

 

procedure TForm1.Button3Click(Sender: TObject);

var

 TotalTime : Cardinal;

begin

TotalTime := GetTickCount;

ADOCommand1.CommandText :='select count(PInt) as ttc from TInteger';

ADOCommand1.Execute;

TotalTime := GetTickCount - TotalTime;

Label3.Caption := inttostr(TotalTime);

 

 

 

 

 

TotalTime := GetTickCount;

ADOCommand1.CommandText :='select count(PGuid) as ttc from TGuid';

ADOCommand1.Execute;

TotalTime := GetTickCount - TotalTime;

Label5.Caption := inttostr(TotalTime);

 

 

 

 

 

TotalTime := GetTickCount;

ADOCommand1.CommandText :='select count(PComb) as ttc from Tcomb';

ADOCommand1.Execute;

TotalTime := GetTickCount - TotalTime;

Label7.Caption := inttostr(TotalTime);

 

 

 

 

 

TotalTime := GetTickCount;

ADOCommand1.CommandText :='select count(PComb) as ttc from Tcomb2';

ADOCommand1.Execute;

TotalTime := GetTickCount - TotalTime;

Label9.Caption := inttostr(TotalTime);

end;

 

 

 

 

 

end.

 

 

 

 

 

很简单的代码,无需加说明了.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值