BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Which method of accessing the fields is the slowest?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Eduardo A. Salgado
Guest





PostPosted: Tue Jun 14, 2005 5:49 pm    Post subject: Which method of accessing the fields is the slowest? Reply with quote



Is FieldByName('') the slowest method of accessing the data in a field?

This procedure seems much faster.

begin
try
// Init the field only once
flStation := ds.FieldByName('Station');

// This while statement now blazes.
while not ds.Eof do
begin
s := flStation.AsString;
...
ds.Next;
end; { while not ds.Eof }
finally
...
end; { try finally }

Which is the fastest way to access the fields? Is there a link to a
test site with stats?

Thanks!

- Eduardo
Accept the challenges so that you can feel
the exhilaration of victory.
-- General George S. Patton

Eminent Domain Software
"Custom Software Development For Your Domain"

Makers of EDSSpell, EDSPrint, EDSZipCodes and
XSpell, the IDE Expert.
Back to top
Wayne Niddery [TeamB]
Guest





PostPosted: Tue Jun 14, 2005 5:58 pm    Post subject: Re: Which method of accessing the fields is the slowest? Reply with quote



Eduardo A. Salgado wrote:
Quote:
Is FieldByName('') the slowest method of accessing the data in a
field?

Yes because it must search through the list of fields looking for the
specified name. In *most* applications this represents a very tiny overhead
that is never noticed, however in specific cases where iteration of records
is involved, it can definitely add up to a noticeable impact. You have found
the solution..

Quote:
// Init the field only once
flStation := ds.FieldByName('Station');
while not ds.Eof do

This technique provides the best of both worlds - avoids design-time field
definitions which has its own trade-offs, and provides performance when
really needed. For all other non-time-critical code I use FieldByName.

--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
SpaceShipOne; GovernmentZero



Back to top
Craig Stuntz [TeamB]
Guest





PostPosted: Tue Jun 14, 2005 6:04 pm    Post subject: Re: Which method of accessing the fields is the slowest? Reply with quote



Eduardo A. Salgado wrote:

Quote:
Is FieldByName('') the slowest method of accessing the data in a
field?

It's slow, but to *really* use the slowest way you should pair it with
the .Value property and get a variant conversion as well... :)

--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
Useful articles about InterBase development:
http://blogs.teamb.com/craigstuntz/category/21.aspx

Back to top
Del M
Guest





PostPosted: Tue Jun 14, 2005 10:45 pm    Post subject: Re: Which method of accessing the fields is the slowest? Reply with quote

And then move each field to a variable and reference the variable in the
code. ..... oh ..and be sure to create and destroy the variables in between
setting their value ... that way you save the overhead of defining a
variable that has to be resolved at compile time ... :-)


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.