473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

which approach is out performing the other ?

Hi...

I have the following two code excerpts. It basically reads data froma
dataReader and adds it
to a collection....

Excerpt A:
*******

With ProjectData
While .Read
Me.Add(DirectCast(.Item("project_id"), Guid), _
DirectCast(.Item("start_date"), DateTime), _
DirectCast(.Item("end_date"), DateTime), _
DirectCast(.Item("priority"), Integer), _
DirectCast(.Item("description"), String), _
DirectCast(.Item("project_manager"), String)
End While
End With
Excerpt B:
********
Nov 20 '05 #1
16 1119
YOu didn't post anything with B to compare to. In general, you want to use
indexes though.

Me.Add(.Item("project_id"))

instead use Me.Add(Item(0))

You can use DataReader.GetOrdingal outside of the While loop which will let
you use a readable name but still use the indexes....if you use strings for
the columnames, they need to be resolved over and over again.

Bill Vaughn recommends using an enum which even cuts out the overhead of
GetOrdinal.
"tinman" <dw****@yahoo.com> wrote in message
news:Ob**************@tk2msftngp13.phx.gbl...
Hi...

I have the following two code excerpts. It basically reads data froma
dataReader and adds it
to a collection....

Excerpt A:
*******

With ProjectData
While .Read
Me.Add(DirectCast(.Item("project_id"), Guid), _
DirectCast(.Item("start_date"), DateTime), _
DirectCast(.Item("end_date"), DateTime), _
DirectCast(.Item("priority"), Integer), _
DirectCast(.Item("description"), String), _
DirectCast(.Item("project_manager"), String)
End While
End With
Excerpt B:
********

Nov 20 '05 #2
Tinman,
In addition to William's comments.

Using the DataReader.Get*Type* methods are easier then using DirectCast. The
Get*Type* methods require the ordinal, you can use either GetOrdinal before
the loop, or define an Enum if you know the specific fields returned.

Something like:

Enum Field
project_id
start_date
end_date
priority
description
project_manager
End Enum
Me.Add(.GetGuid(Field.project_id)), _
.GetDateTime(Field.start_date)), _
.GetDateTime(Field.end_date)), _
.GetInt32(Field.priority)), _
.GetString(Field.description)), _
.GetString(Field.project_manager))
David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS Press is
both a good Tutorial on ADO.NET plus an excellent desk reference once you
know ADO.NET.

Hope this helps
Jay

"tinman" <dw****@yahoo.com> wrote in message
news:Ob****************@tk2msftngp13.phx.gbl... Hi...

I have the following two code excerpts. It basically reads data froma
dataReader and adds it
to a collection....

Excerpt A:
*******

With ProjectData
While .Read
Me.Add(DirectCast(.Item("project_id"), Guid), _
DirectCast(.Item("start_date"), DateTime), _
DirectCast(.Item("end_date"), DateTime), _
DirectCast(.Item("priority"), Integer), _
DirectCast(.Item("description"), String), _
DirectCast(.Item("project_manager"), String)
End While
End With
Excerpt B:
********

Nov 20 '05 #3
Hi Bill,
YOu didn't post anything with B to compare to. In general, you want to use indexes though.

Me.Add(.Item("project_id"))

instead use Me.Add(Item(0))

You can use DataReader.GetOrdingal outside of the While loop which will let you use a readable name but still use the indexes....if you use strings for the columnames, they need to be resolved over and over again


I respectfully do not agree.

When this becomes an issue you should direct stop using OOP.

It has nothing to do with OOP, however OOP gives also a small amount of
overhead comparing that by writting direct commands. The overhead is direct
in the memory and processor area, and from an ammount, which is probably
1000000000000000000000000 times less than one long mouse stroke.

Just my opinion.

cor
Nov 20 '05 #4
Hi Jay,

I respectfully do not agree. See my comments with Bill when you do want to
react, I wrote it at Bill with you in mind..

Cor
Nov 20 '05 #5
Cor, I'm not following you here. If you use GetOrdinal, you can use a clear
name and have Index based lookups. If you use an enum you can use the same
name and still have index based lookups. So you get all the clarity, but
don't have to take the performance hit.

I don't see what you have to loose by using

int project_id = myDataReader.GetOrdinal("project_id")
or
enum myProject
project_it = 0
end enum

and me.Add(.Item(project_id))
or me.Add(.Item(project_id)) 'w/enum

or me.Add(.Item("project_id")

from a maintainability point of view, it's virtually identical, but it
performs a lot better, particularly on large datasets.

Maybe I misunderstood your point or do you disagree with this ?
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OY**************@TK2MSFTNGP11.phx.gbl...
Hi Bill,
YOu didn't post anything with B to compare to. In general, you want to use
indexes though.

Me.Add(.Item("project_id"))

instead use Me.Add(Item(0))

You can use DataReader.GetOrdingal outside of the While loop which will

let
you use a readable name but still use the indexes....if you use strings

for
the columnames, they need to be resolved over and over again


I respectfully do not agree.

When this becomes an issue you should direct stop using OOP.

It has nothing to do with OOP, however OOP gives also a small amount of
overhead comparing that by writting direct commands. The overhead is

direct in the memory and processor area, and from an ammount, which is probably
1000000000000000000000000 times less than one long mouse stroke.

Just my opinion.

cor

Nov 20 '05 #6
Cor,
Its your right to not agree!

However as Bill indicated, I'm not following your reply to Bill. Using the
Ordinal or the name has nothing to do with OOP, it has to do with how the
DataReader class was implemented. Looking up the item based on the string is
generally slower then looking up the item based on the ordinal position
(with a DataReader). This is documented in Sceppa's book and I believe Bill
Vaughn has also documented it.

About the only time I see using the name lookups is when you have Option
Strict Off, which itself has benefits & pitfalls. For me Option Strict On is
the better way to go...

Just a thought
Jay

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Ov****************@TK2MSFTNGP09.phx.gbl...
Hi Jay,

I respectfully do not agree. See my comments with Bill when you do want to
react, I wrote it at Bill with you in mind..

Cor

Nov 20 '05 #7

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:um****************@TK2MSFTNGP09.phx.gbl...
Cor,
Its your right to not agree! Absolutely, and it makes the NG's a better place
However as Bill indicated, I'm not following your reply to Bill. Using the
Ordinal or the name has nothing to do with OOP, it has to do with how the
DataReader class was implemented. Agreed

Looking up the item based on the string is generally slower then looking up the item based on the ordinal position
(with a DataReader). Not generally, always. Its only a matter of how much. And the same holds for datatables too.
This is documented in Sceppa's book and I believe Bill Vaughn has also documented it. Yes, and Bill is quite vocal on this, that's why he came up with the enum
method...to avoid the overhead of using GetOrdinal..so you get the best of
both worlds witha maximum of performance
About the only time I see using the name lookups is when you have Option
Strict Off, which itself has benefits & pitfalls. For me Option Strict On is the better way to go...
Option Strict Off is a Crime against Humanity. It's a tragedy it's not On
by default. Many more pitfalls than benefits...out of curiosity, are there
any other benefits? Other than the same ones you get by turning off option
explicit?
Just a thought
Jay

Cheers,

Bill "Cor Ligthert" <no**********@planet.nl> wrote in message
news:Ov****************@TK2MSFTNGP09.phx.gbl...
Hi Jay,

I respectfully do not agree. See my comments with Bill when you do want to react, I wrote it at Bill with you in mind..

Cor


Nov 20 '05 #8
Hi Bill,

What I mean is that simplisity is also a benefit. Without even testing I am
sure that a non strong typed dataset will perform better than a typed
dataset.

And although that people prefer the typed dataset, just because it is better
readable.

I am not with those who say you should always to use it.

However that does not mean that I think that there where it is better for
the readability not even to use the datafieldnames or to make constructions
which help you to avoid that.

But I do not agree that it is "Better"

However just my thought about this.

Cor
Nov 20 '05 #9
Hi Jay B.
However as Bill indicated, I'm not following your reply to Bill. Using the
Ordinal or the name has nothing to do with OOP,
That is what I started with, however making good compact readable programs
is *one* of the goals of OOP, that does sometimes conflict with the
performance and in that sense I wrote it, while I was saying it had nothing
to do with OOP.

My opinion is that a very few loss of performance sometimes has to be
accepted for better readability. While there are some cases where that is
not when the process is highly repeatable.

However for that it is in my opinion important if it is a processor/memory
or processor/device operation. For the dataset which is in this case in the
first (it does not affect the real reading) I cannot find any reason to do
something for performance. (In opposite from that I am always saying that it
is in my opinion it is wise to keep it as small as possible, because that is
a processor/device operation)
About the only time I see using the name lookups is when you have Option

Strict Off, which itself has benefits & pitfalls. For me Option Strict On

is the better way to go...

Who wrote that that was not, I do not see the meaning of this sentense in
what I wrote, did I deny that somewhere in this messages.

I thought that with Armin, I am the one who write that the most in this
newsgroup (and I think that the last time I write that even more than
Armin).

:-)

Cor

Nov 20 '05 #10
Hi Bill,

I correct my own message, I edited it to many times
And although that people prefer the typed dataset, just because it is better readable. And therefore ...............
I am not with those who say you should always to use it. ................always use it
But I do not agree that it is "Better"

But I do not agree that direct indexing is "Better"

(Although I am that lazy that I often use it in a for indexed loop).

Cor
Nov 20 '05 #11

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi Bill,

What I mean is that simplisity is also a benefit. Without even testing I am sure that a non strong typed dataset will perform better than a typed
dataset.
Actually, the exact opposite is true, but I understand your point.
And although that people prefer the typed dataset, just because it is better readable. and much faster ;-) I am not with those who say you should always to use it.

However that does not mean that I think that there where it is better for
the readability not even to use the datafieldnames or to make constructions which help you to avoid that.

But I do not agree that it is "Better"
Ok, but in the above example, you could have it both ways, readable and
speed. You have a great point, it's just that in this case, there's not a
trade off. If there were, yes, I'd agree with you.
However just my thought about this.

Cor

Nov 20 '05 #12
Ok, but what about using GetOrdinal or the Enum. It's just as readable, the
only thing is Columname vs. "ColumnName" that's only two qoute marks. But
you get much more speed with the ColumnName if you used an Enum or
GetOrdinal.

Wouldn't you also agree that customers decide if they can live with the
performance? A lot of times things perform well in test, then get out in
the field and get sluggish once the DB for isntance, starts filling up.
Then you need some serious rework in many instances. I think you cna strike
a balance, and in this case, you can have it both ways using indexes ;-)

But this certainly isn't the case most of the time, in those instances, I
totally agree with you.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
Hi Bill,

I correct my own message, I edited it to many times
And although that people prefer the typed dataset, just because it is

better
readable.

And therefore ...............
I am not with those who say you should always to use it.

...............always use it
But I do not agree that it is "Better"

But I do not agree that direct indexing is "Better"

(Although I am that lazy that I often use it in a for indexed loop).

Cor

Nov 20 '05 #13
>
Actually, the exact opposite is true, but I understand your point.


Do you mean because the adapter.fill is not used in that when it is made by
the designer?

Cor
Nov 20 '05 #14
Bill,
About the only time I see using the name lookups is when you have Option
Strict Off, which itself has benefits & pitfalls. For me Option Strict
On is
the better way to go...
Option Strict Off is a Crime against Humanity. It's a tragedy it's not On
by default. Many more pitfalls than benefits...out of curiosity, are

there any other benefits? Other than the same ones you get by turning off option explicit?
Option Strict Off allows Late Binding, Late Binding is a form of
Polymorphism, Polymorphism can simplify your programs. Smalltalk is
effectively all late bound polymorphism.

Late Binding also simplifies some COM interop code, for example the CDO
1.2.1 class library was designed with VBScript in mind, in VBScript every
thing is an Object & every thing is Late Bound. Seeing as every thing is an
Object, all the properties in CDO 1.2.1 are Object (not strongly typed). If
you use CDO 1.2.1 from VB.NET or C# you need to cast all the properties into
strongly typed variables or rely on late binding.

Normally I have Option Strict On & Option Explicit On explicitly stated in
each source file, I do not rely on project options or VS.NET options. If I
need to use Late Binding (Option Strict Off) as for example I have a lot of
CDO 1.2.1 code then I will encapsulate that in a single class and have that
class file explicitly Option Strict Off.

Note using a healthy dose of DirectCasting you can use CDO 1.2.1 with Option
Strict On, however the code is harder to read...

Hope this helps
Jay

"William Ryan eMVP" <do********@comcast.nospam.net> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:um****************@TK2MSFTNGP09.phx.gbl...

<<snip>>
Nov 20 '05 #15
No, referencing anything with a Strongly typed dataset is much faster b/c
it's typed. Just like Option Strict On vs. Off.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eH**************@TK2MSFTNGP10.phx.gbl...

Actually, the exact opposite is true, but I understand your point.
Do you mean because the adapter.fill is not used in that when it is made

by the designer?

Cor

Nov 20 '05 #16
Hi Bill,
No, referencing anything with a Strongly typed dataset is much faster b/c
it's typed. Just like Option Strict On vs. Off.


This would implied for me that the dataadapter.fill from a strongly typed
dataset would read the schema and from a non strongly typed dataset not.

You know that that is not true.

However I think it is better to make this thread OT otherwise we go to far
in it.

It is not a religion or something.

Cor
Nov 20 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Brad Marts | last post by:
I would like to have a function that takes as an argument a base class but performs differently depending on which type of derived class is passed. Can I tell which derived class is passed? For...
17
by: lawrence | last post by:
How is it possible that the question "How do I detect which browser the user has" is missing from this FAQ: http://www.faqts.com/knowledge_base/index.phtml/fid/125 and is only here on this...
2
by: Colleyville Alan | last post by:
I have been working on a project that uses MS Access to get mutual fund performance and write it to a spreadsheet in a formatted manner. The user inputs the company name, the database looks at the...
20
by: Steve Jorgensen | last post by:
Hi all, I've just finished almost all of what has turned out to be a real bear of a project. It has to import data from a monthly spreadsheet export from another program, and convert that into...
10
by: Mark Givens | last post by:
Ok, I have read more website tutorials on C# arrays than I really wanted too and am still completely blured on the subject. I normally develop websites using PHP/MySql, but have been forced into a...
14
by: J.S. | last post by:
In a Windows Form application, which is the better method to concatenate large blocks of code? 1. Reading the text from text files. 2. Adding the text to the VB file itself? Thanks! J.S. ...
0
by: Mossman | last post by:
Hello, I posted this problem in another thread and received no response. I need some input at what to look at next. So, if anyone out there as any suggestions, please respond to this message....
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.