| 導購 | 订阅 | 在线投稿
分享
 
 
 

Integer GUID和Comb做主鍵的效率測試(Delphi+access)(二)

來源:互聯網網民  2006-02-01 01:53:41  評論

看一下我們的表格構:

Integer GUID和Comb做主鍵的效率測試(Delphi+access)(二)

Integer GUID和Comb做主鍵的效率測試(Delphi+access)(二)

TInteger表是用自動加1字段做爲主鍵(PInt)

TGuid表是用GUID做爲主鍵(PGUID)

PComb表是用Comb做爲主鍵(PComb)

PComb2表是用改過後的Comb做爲主鍵(PComb,第四種情況)

在這四表中還有一列,NInt,用于插入一個數值,隨機的,沒有什麽實際的意義

下面先看一下我們的測試界面:

Integer GUID和Comb做主鍵的效率測試(Delphi+access)(二)

Integer GUID和Comb做主鍵的效率測試(Delphi+access)(二)

插入數據是指在數據庫的四個表中插入指定條目的數據.

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.

很簡單的代碼,無需加說明了.

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
看一下我們的表格構: [url=/bbs/detail_150077.html][img]http://dev.csdn.net/images/blog_csdn_net/newsunet/1.JPG[/img][/url] [url=/bbs/detail_150077.html][img]http://dev.csdn.net/images/blog_csdn_net/newsunet/1.JPG[/img][/url] TInteger表是用自動加1字段做爲主鍵(PInt) TGuid表是用GUID做爲主鍵(PGUID) PComb表是用Comb做爲主鍵(PComb) PComb2表是用改過後的Comb做爲主鍵(PComb,第四種情況) 在這四表中還有一列,NInt,用于插入一個數值,隨機的,沒有什麽實際的意義 下面先看一下我們的測試界面: [url=/bbs/detail_150077.html][img]http://dev.csdn.net/images/blog_csdn_net/newsunet/0.JPG[/img][/url] [url=/bbs/detail_150077.html][img]http://dev.csdn.net/images/blog_csdn_net/newsunet/0.JPG[/img][/url] 插入數據是指在數據庫的四個表中插入指定條目的數據. 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. 很簡單的代碼,無需加說明了.
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 
 熱帖排行
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有