Subject Re: [IBO] IBO 10x slower than ibx doing Insert
Author Magni Thor Mortensen
Thanks
The BeginBusy and EndBusy did the trick, I'm getting comparable speed now

Magni

Jason Wharton wrote:
>
> Most likely it is because you have a flickering SQL hourglass.
>
> Use the BeginBusy() and EndBusy methods of the query in a try finally and
> that should make things more equal. It's also important that you don't use
> ParamByName() type of references but static ones.
>
> Here's how I would write what you've got:
>
> 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);
> IBOc.DatabaseName := 'c:\firebird\examples\EMPLOYEE.FDB';
> IBOc.Username := 'sysdba';
> IBOc.Password := 'masterkey';
>
> IBOt := TIB_Transaction.Create(IBOc);
> IBOt.IB_Connection := IBOc;
>
> IBOq := TIB_DSQL.Create(IBOc);
> IBOq.IB_Connection := IBOc;
> IBOq.IB_Transaction := IBOt;
> IBOq.SQL.Text := 'INSERT INTO COUNTRY (COUNTRY, CURRENCY) VALUES
> (:COUNTRY, :CURRENCY)';
>
> IBOc.Connect;
> IBOq.Prepare;
> start := Now;
> IBOc.BeginBusy( false );
> try
> IBOt.StartTransaction;
> try
> for i := 0 to 10000 do begin
> IBOq.Params[0].AsString := 'a'+IntToStr(i);
> IBOq.Params[1].AsString := 'bla';
> IBOq.Execute;
> end;
> IBOt.Commit;
> except
> IBOt.Rollback;
> raise;
> end;
> finally
> IBOc.EndBusy;
> end;
> stop := Now;
> dur := stop - start;
> showMessage(FormatDateTime('hh:ss:zz',dur));
> end;
>
> Jason
>
> > -----Original Message-----
> > From: IBObjects@yahoogroups.com <mailto:IBObjects%40yahoogroups.com>
> [mailto:IBObjects@yahoogroups.com <mailto:IBObjects%40yahoogroups.com>]On
> > Behalf Of Magni Thor Mortensen
> > Sent: Monday, July 10, 2006 3:37 PM
> > To: IBObjects@yahoogroups.com <mailto:IBObjects%40yahoogroups.com>
> > Subject: [IBO] IBO 10x slower than ibx doing Insert
> >
> >
> > 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;
> >
> >
> >
> >
> >
> > ------------------------ Yahoo! Groups Sponsor
> > --------------------~-->
> > Something is new at Yahoo! Groups. Check out the enhanced
> > email design.
> > http://us.click.yahoo.com/SISQkA/gOaOAA/yQLSAA/PhFolB/TM
> <http://us.click.yahoo.com/SISQkA/gOaOAA/yQLSAA/PhFolB/TM>
> > ----------------------------------------------------------
> > ------~->
> >
> > __________________________________________________________
> > _____________
> > IB Objects - direct, complete, custom connectivity to
> > Firebird or InterBase
> > without the need for BDE, ODBC or any other layer.
> > __________________________________________________________
> > _____________
> > http://www.ibobjects.com <http://www.ibobjects.com> - your IBO
> community resource for
> > Tech Info papers,
> > keyword-searchable FAQ, community code contributions and more
> > !
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
>
>