分享
 
 
 

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

王朝delphi·作者佚名  2006-02-01
窄屏简体版  字體: |||超大  

看一下我们的表格构:

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.

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有