Subject | IBO 10x slower than ibx doing Insert |
---|---|
Author | Magni Thor Mortensen |
Post date | 2006-07-10T22:36:36Z |
Why is IBO almost 10x slower than InterBase Express when doing bulk
inserts with prepared statements ?
The following test takes ~10 seconds with IBO, but only ~ 1 second with
IBX with 1.000 inserts,
10.000 takes ~ 45 seconds with IBO, but only ~ 10 with IBX
I'm running firebird 1.5.3.4870 superserver on win xp
Using delphi 7 and IBO 4.6.b, and the IBX that came with D7
best regards
Magni
test :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
IB_Components
,IBSQL
, IBDatabase
, DB
;
procedure TForm1.Button1Click(Sender: TObject);
var
IBOc : TIB_Connection;
IBOt : TIB_Transaction;
IBOq : TIB_DSQL;
start, stop, dur : TTime;
i : Integer;
begin
IBOc := TIB_Connection.Create(nil);
IBOt := TIB_Transaction.Create(nil);
IBOq := TIB_DSQL.Create(nil);
IBOc.DatabaseName := 'c:\firebird\examples\EMPLOYEE.FDB';
IBOc.Username := 'sysdba';
IBOc.Password := 'masterkey';
IBOc.Connect;
IBOq.IB_Connection := IBOc;
IBOq.SQL.Text := 'INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES
(:COUNTRY, :CURRENCY)';
IBOq.Prepare;
start := Now;
IBOt.StartTransaction;
for i := 0 to 10000 do begin
IBOq.ParamByName('COUNTRY').AsString := 'a'+IntToStr(i);
IBOq.ParamByName('CURRENCY').AsString := 'bla';
IBOq.Execute;
end;
IBOt.Commit;
stop := Now;
dur := stop - start;
showMessage(FormatDateTime('hh:ss:zz',dur));
end;
procedure TForm1.Button2Click(Sender: TObject);
var
IBd : TIBDatabase;
IBt : TIBTransaction;
IBq : TIBSQL;
start, stop, dur : TTime;
i : Integer;
begin
IBd := TIBDatabase.Create(nil);
IBt := TIBTransaction.Create(nil);
IBd.DefaultTransaction := IBt;
IBq := TIBSQL.Create(nil);
IBd.DatabaseName := 'c:\firebird\examples\EMPLOYEE.FDB';
IBd.Params.Values['user_name'] := 'sysdba';
IBd.Params.Values['password'] := 'masterkey';
IBd.LoginPrompt := False;
IBd.Connected := True;
IBq.Database := IBd;
IBq.Transaction := IBt;
IBt.StartTransaction;
IBq.SQL.Text := 'INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES
(:COUNTRY, :CURRENCY)';
IBq.Prepare;
start := Now;
for i := 0 to 10000 do begin
IBq.ParamByName('COUNTRY').AsString := 'b'+IntToStr(i);
IBq.ParamByName('CURRENCY').AsString := 'bla';
IBq.ExecQuery;
end;
IBt.Commit;
stop := Now;
dur := stop - start;
showMessage(FormatDateTime('hh:ss:zz',dur));
end;
inserts with prepared statements ?
The following test takes ~10 seconds with IBO, but only ~ 1 second with
IBX with 1.000 inserts,
10.000 takes ~ 45 seconds with IBO, but only ~ 10 with IBX
I'm running firebird 1.5.3.4870 superserver on win xp
Using delphi 7 and IBO 4.6.b, and the IBX that came with D7
best regards
Magni
test :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
IB_Components
,IBSQL
, IBDatabase
, DB
;
procedure TForm1.Button1Click(Sender: TObject);
var
IBOc : TIB_Connection;
IBOt : TIB_Transaction;
IBOq : TIB_DSQL;
start, stop, dur : TTime;
i : Integer;
begin
IBOc := TIB_Connection.Create(nil);
IBOt := TIB_Transaction.Create(nil);
IBOq := TIB_DSQL.Create(nil);
IBOc.DatabaseName := 'c:\firebird\examples\EMPLOYEE.FDB';
IBOc.Username := 'sysdba';
IBOc.Password := 'masterkey';
IBOc.Connect;
IBOq.IB_Connection := IBOc;
IBOq.SQL.Text := 'INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES
(:COUNTRY, :CURRENCY)';
IBOq.Prepare;
start := Now;
IBOt.StartTransaction;
for i := 0 to 10000 do begin
IBOq.ParamByName('COUNTRY').AsString := 'a'+IntToStr(i);
IBOq.ParamByName('CURRENCY').AsString := 'bla';
IBOq.Execute;
end;
IBOt.Commit;
stop := Now;
dur := stop - start;
showMessage(FormatDateTime('hh:ss:zz',dur));
end;
procedure TForm1.Button2Click(Sender: TObject);
var
IBd : TIBDatabase;
IBt : TIBTransaction;
IBq : TIBSQL;
start, stop, dur : TTime;
i : Integer;
begin
IBd := TIBDatabase.Create(nil);
IBt := TIBTransaction.Create(nil);
IBd.DefaultTransaction := IBt;
IBq := TIBSQL.Create(nil);
IBd.DatabaseName := 'c:\firebird\examples\EMPLOYEE.FDB';
IBd.Params.Values['user_name'] := 'sysdba';
IBd.Params.Values['password'] := 'masterkey';
IBd.LoginPrompt := False;
IBd.Connected := True;
IBq.Database := IBd;
IBq.Transaction := IBt;
IBt.StartTransaction;
IBq.SQL.Text := 'INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES
(:COUNTRY, :CURRENCY)';
IBq.Prepare;
start := Now;
for i := 0 to 10000 do begin
IBq.ParamByName('COUNTRY').AsString := 'b'+IntToStr(i);
IBq.ParamByName('CURRENCY').AsString := 'bla';
IBq.ExecQuery;
end;
IBt.Commit;
stop := Now;
dur := stop - start;
showMessage(FormatDateTime('hh:ss:zz',dur));
end;