Subject | Re: Re[2]: [IBO] Questions of style, slightly off topic. |
---|---|
Author | Brian Nuckels |
Post date | 2001-01-25T20:12:23Z |
Yep. If you refer to it multiple times this way, you can notice it. In
reality, this is accessing the default property of the component,
FieldValues.
From the help on TDataSet:
"Because FieldValues always uses Variants, it may be a somewhat slower
method of accessing data, than using a field's native format (i.e., using a
field's AsXXX property), especially in applications that process large
amounts of data."
While we're talking about speed, you can acquire unnecessary overhead by
repeatedly accessing it like this too:
query.FieldByName('COL').AsString (where field is a string field)
If it's NOT a string field I would imagine this is calling a conversion
function every time, and it also is probably calling several methods to get
the data from memory or disk. Although these methods are probably optimized
for speed, if you need to read the value many times and are concerned with
speed consider calling FieldByName.AsString once and storing it in a
well-named local variable so that you can work with it more directly from
that point forward. This is a good rule to follow in any area where you
seem to have a bottleneck. If you find that tight loop where you keep
accessing a checkbox's Checked property over and over is slower than it
should be, use a standard boolean varible (as long as the subsequent state
of the checkbox doesn't matter once the code begins executing) and surprise,
it's faster.
Remember that with a property, there is a good chance of slight overhead
from a function call, because many properties get to their data through an
accessor method. I'm not advocating throwing out all the readability
benefits that come from named objects with properties, but it's good to be
aware what's really going on behind the scenes so that you can find ways to
speed optimize if necessary. I usually am selective about which way I do
it, based on the situation. If I can, I do it the more readable way, but if
I know I'll be reading an unchanging property value many times, I always use
a variable assignment.
reality, this is accessing the default property of the component,
FieldValues.
From the help on TDataSet:
"Because FieldValues always uses Variants, it may be a somewhat slower
method of accessing data, than using a field's native format (i.e., using a
field's AsXXX property), especially in applications that process large
amounts of data."
While we're talking about speed, you can acquire unnecessary overhead by
repeatedly accessing it like this too:
query.FieldByName('COL').AsString (where field is a string field)
If it's NOT a string field I would imagine this is calling a conversion
function every time, and it also is probably calling several methods to get
the data from memory or disk. Although these methods are probably optimized
for speed, if you need to read the value many times and are concerned with
speed consider calling FieldByName.AsString once and storing it in a
well-named local variable so that you can work with it more directly from
that point forward. This is a good rule to follow in any area where you
seem to have a bottleneck. If you find that tight loop where you keep
accessing a checkbox's Checked property over and over is slower than it
should be, use a standard boolean varible (as long as the subsequent state
of the checkbox doesn't matter once the code begins executing) and surprise,
it's faster.
Remember that with a property, there is a good chance of slight overhead
from a function call, because many properties get to their data through an
accessor method. I'm not advocating throwing out all the readability
benefits that come from named objects with properties, but it's good to be
aware what's really going on behind the scenes so that you can find ways to
speed optimize if necessary. I usually am selective about which way I do
it, based on the situation. If I can, I do it the more readable way, but if
I know I'll be reading an unchanging property value many times, I always use
a variable assignment.
----- Original Message -----
From: "Carlos H. Cantu" <ibo@...>
To: "Paul Gallagher" <IBObjects@egroups.com>
Sent: Thursday, January 25, 2001 1:11 PM
Subject: Re[2]: [IBO] Questions of style, slightly off topic.
> If I remember correctly this is the "slowest" method to access a field...
I
> think it is because the value is accessed as a variant (variant = extra
> work :).
>
> []s
>
> Carlos
> WarmBoot Informatica - http://www.warmboot.com.br
> Interbase-BR - http://www.interbase-br.com
>
> PG> I usually use this method. It works in almost all situations.
>
> PG> IB_Query1['FIELDNAME']
>
> PG> Paul Gallagher
>
> PG> ----- Original Message -----
> PG> From: "Joseph Carney" <jcarney@...>
> PG> To: <IBObjects@egroups.com>
> PG> Sent: Thursday, January 25, 2001 8:46 AM
> PG> Subject: [IBO] Questions of style, slightly off topic.
>
>
> >> I am currently in a discussion with another programmer about coding
style,
> >> with each of us
> >> having different opinions.
> >>
> >> Normally when I am referencing either an IBOQuery or a IB_Query I
> PG> reference
> >> with:
> >> query.fieldbyname('fieldname').AsString.....
> >> My compatriot seems to prefer:
> >> query.Fields.FieldByName('fieldname').AsString...
> >>
> >> My question is, which method is more efficient in terms of runtime
> PG> execution
> >> speed?
> >> Is the extra typing worth it?
> >>
> >> Just trying to settle a friendly difference of opinion.
> >>
> >>
> >> Joe Carney
> >> West Palm Beach, FL
> >> jcarney@...