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

看一下我們的表格構:

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.

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

 
Integer GUID和Comb做主鍵的效率測試(Delphi+access)(三)
下面是測試數據插入數據測試1. 一次插入100條記錄(單位:毫秒):Integer GUID Comb Comb260 90 30 4070 80 81 5060 90 50 5060 80 80 ...查看完整版>>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)(一)
對于數據系統表的主鍵選擇不是什麽大不了的事,可能對于一些朋友來說,這非常容易,可是卻不是如此的簡單,對于某些應用來說,自動加1字段就可以了,但是對于某些系統來說,選擇自動加1 的方式會帶來很大的麻煩,在此種方法的...查看完整版>>Integer GUID和Comb做主鍵的效率測試(Delphi+access)(一)
 
Java執行效率測試:Ubuntu全面領先 Vista
Java執行效率測試:Ubuntu全面領先 Vista
  據了解,phoronix(業內一個知名的網站,其經常發布硬件性能測評以及 linux 系統相關的性能測評)昨日對java在Ubuntu Linux 與Windows Vista上的執行效率進行了測試,結果令人驚奇,Ubuntu Linux 竟然全面領先 Win...查看完整版>>Java執行效率測試:Ubuntu全面領先 Vista
 
體驗高端!Core i7-920遊戲效率測試
  Core i7的性能毋庸置疑,不過多個核心的執行效率又如何呢?好在當前的主板大都提供了激活核心數量選項,可以很方便地進行對比測試,看看現在的3D遊戲到底需要幾個核心才能流暢運行。測試平台:處理器:Core i7-9...查看完整版>>體驗高端!Core i7-920遊戲效率測試