| View previous topic :: View next topic |
| Author |
Message |
Eduardo A. Salgado Guest
|
Posted: Tue Jun 14, 2005 5:49 pm Post subject: Which method of accessing the fields is the slowest? |
|
|
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
|
Posted: Tue Jun 14, 2005 5:58 pm Post subject: Re: Which method of accessing the fields is the slowest? |
|
|
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
|
Posted: Tue Jun 14, 2005 6:04 pm Post subject: Re: Which method of accessing the fields is the slowest? |
|
|
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
|
Posted: Tue Jun 14, 2005 10:45 pm Post subject: Re: Which method of accessing the fields is the slowest? |
|
|
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 |
|
 |
|