Ordinal Versus Columnname

K

Keith N

I need some references to some hard facts to why the Ordinal value is a
better choice than the column/field name when extracting information of a
row in ADO.NET.

Anybody have some good reference with numbers that I can show to someone.

Peace,
Keith
 
P

Per Hornshøj-Schierbeck

I think most books on ADO.NET tells you why. It has to do with using the
field name requires the object to loop through the columns checking their
names before deciding which index it is. Using the name instead of the
ordinal value makes your code easier to read, but if you require speed in a
long loop use the ordinal value.

I used the DevPartner Studio from Compuware to measure performance so i know
for a fact, that in a test environment i ran with two different methods -
one with ordinal values, the other with string value - the ordinal call was
between 8 and 10 times faster. Both are pretty quick and if all you need is
read a few values (not inside a loop) i'd probably still use the string
value so it would be easier to read later (or edit/change the sql), but if
you're looping through 1000 records trying to match something, then go for
the ordinal values.

Per
 
S

Steve Drake

If you need speed and readability, you can use ENUM eg:

enum tablename
{
ID,
Name,
Other
};

and your code could read :

YourDataSetOrWhatEver.Tables[0].Rows[0][tablename.ID]
YourDataSetOrWhatEver.Tables[0].Rows[0][tablename.Name]

Cheers

Steve
 
W

William \(Bill\) Vaughn

I'm with Steve. However, my tests show that strongly typed DataSets are
slightly faster than enumerations, but not enough to make me use STDs
everywhere. Enumerations (in my tests) are an order of magnitude faster
(2000 vs 200 ticks). How much you benefit from this really depends on how
often the references are made. While it might save 10% of the time to
execute a function, the function might play a .1% role in the overall
performance of the application.

--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

Steve Drake said:
If you need speed and readability, you can use ENUM eg:

enum tablename
{
ID,
Name,
Other
};

and your code could read :

YourDataSetOrWhatEver.Tables[0].Rows[0][tablename.ID]
YourDataSetOrWhatEver.Tables[0].Rows[0][tablename.Name]

Cheers

Steve

Per Hornshøj-Schierbeck said:
I think most books on ADO.NET tells you why. It has to do with using the
field name requires the object to loop through the columns checking their
names before deciding which index it is. Using the name instead of the
ordinal value makes your code easier to read, but if you require speed
in
a
long loop use the ordinal value.

I used the DevPartner Studio from Compuware to measure performance so i know
for a fact, that in a test environment i ran with two different methods -
one with ordinal values, the other with string value - the ordinal call was
between 8 and 10 times faster. Both are pretty quick and if all you need is
read a few values (not inside a loop) i'd probably still use the string
value so it would be easier to read later (or edit/change the sql), but if
you're looping through 1000 records trying to match something, then go for
the ordinal values.

Per
of
 
K

Kathleen Dollard

Bill,

Could you clarify this?
However, my tests show that strongly typed DataSets are
slightly faster than enumerations, but not enough to make me use STDs
everywhere. Enumerations (in my tests) are an order of magnitude faster
(2000 vs 200 ticks).

What is the second relative to?

Kathleen


William (Bill) Vaughn said:
I'm with Steve. However, my tests show that strongly typed DataSets are
slightly faster than enumerations, but not enough to make me use STDs
everywhere. Enumerations (in my tests) are an order of magnitude faster
(2000 vs 200 ticks). How much you benefit from this really depends on how
often the references are made. While it might save 10% of the time to
execute a function, the function might play a .1% role in the overall
performance of the application.

--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

Steve Drake said:
If you need speed and readability, you can use ENUM eg:

enum tablename
{
ID,
Name,
Other
};

and your code could read :

YourDataSetOrWhatEver.Tables[0].Rows[0][tablename.ID]
YourDataSetOrWhatEver.Tables[0].Rows[0][tablename.Name]

Cheers

Steve

Per Hornshøj-Schierbeck said:
I think most books on ADO.NET tells you why. It has to do with using the
field name requires the object to loop through the columns checking their
names before deciding which index it is. Using the name instead of the
ordinal value makes your code easier to read, but if you require speed
in
a
long loop use the ordinal value.

I used the DevPartner Studio from Compuware to measure performance so
i
know
for a fact, that in a test environment i ran with two different methods -
one with ordinal values, the other with string value - the ordinal
call
was
between 8 and 10 times faster. Both are pretty quick and if all you
need
is
read a few values (not inside a loop) i'd probably still use the string
value so it would be easier to read later (or edit/change the sql),
but
is
 
W

William \(Bill\) Vaughn

Sorry, enumerations are an order of magnitude faster than string-based
object references.

--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

Kathleen Dollard said:
Bill,

Could you clarify this?
However, my tests show that strongly typed DataSets are
slightly faster than enumerations, but not enough to make me use STDs
everywhere. Enumerations (in my tests) are an order of magnitude faster
(2000 vs 200 ticks).

What is the second relative to?

Kathleen


William (Bill) Vaughn said:
I'm with Steve. However, my tests show that strongly typed DataSets are
slightly faster than enumerations, but not enough to make me use STDs
everywhere. Enumerations (in my tests) are an order of magnitude faster
(2000 vs 200 ticks). How much you benefit from this really depends on how
often the references are made. While it might save 10% of the time to
execute a function, the function might play a .1% role in the overall
performance of the application.

--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

Steve Drake said:
If you need speed and readability, you can use ENUM eg:

enum tablename
{
ID,
Name,
Other
};

and your code could read :

YourDataSetOrWhatEver.Tables[0].Rows[0][tablename.ID]
YourDataSetOrWhatEver.Tables[0].Rows[0][tablename.Name]

Cheers

Steve

I think most books on ADO.NET tells you why. It has to do with using the
field name requires the object to loop through the columns checking their
names before deciding which index it is. Using the name instead of the
ordinal value makes your code easier to read, but if you require
speed
in
a
long loop use the ordinal value.

I used the DevPartner Studio from Compuware to measure performance
so
i but go
for is information
of
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top