473,386 Members | 1,821 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,386 software developers and data experts.

Performance Question working with DataRows

1
Which is the more efficient code?

Expand|Select|Wrap|Line Numbers
  1.     Private Sub Test()
  2.         For Each row As DataRow In dtMyTable.Rows
  3.             Debug.Print("{0}", row(0))
  4.         Next
  5.     End Sub
  6.  
  7.     Private Sub Test2()
  8.         If dtMyTable.Rows.Count > 0 Then
  9.             For Each row As DataRow In dtMyTable.Rows
  10.                 Debug.Print("{0}", row(0))
  11.             Next
  12.         End If
  13.     End Sub
  14.  
Looking at the IL, it takes roughly twice as many lines to involve the enumerator as it does to query the RowCount. So does this mean that we should base our decision on the likelihood of the table to contain rows? If it's likely to be empty then using the If Block would provide an earlier exit.

I'm new at reading IL. It appears that if the table contains some rows, two instances of the dataTable is created in the Test2 method. One to check the RowCount and another to invoke the enumerator logic. Does the IL reuse these instances?

I know this might be really splitting hairs but I'd be interested in the best choice for optimum performance. Thanks for your thoughts.
Oct 3 '08 #1
0 946

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dominik Luyten | last post by:
Hi, I would like to format certain DataRows in a Windows.Forms.DataGrid. I know how to do that for the columns, but I cannot find a way to assign a specific font, color etc. to a specific kind...
0
by: Uchiha Jax | last post by:
I have used this method many a time in previous applications without any hitches at all and i'm trying to use it in my current application and it isn't working. The only difference I can see is...
13
by: bjarne | last post by:
Willy Denoyette wrote; > ... it > was not the intention of StrousTrup to the achieve the level of efficiency > of C when he invented C++, ... Ahmmm. It was my aim to match the performance...
5
by: Nathan Sokalski | last post by:
I am writing an ASP.NET application in which I need to copy DataRows from one DataTable to another. When I use code such as the following: temprows = nodes.Select("state='PA'")...
9
by: Brad | last post by:
I have written some code to manipulate data/records in a MASTER (order header) and DETAIL (order details) tables. What I have written is too extensive to post but essentially trying to: 1....
4
by: NormD | last post by:
I've been told that how one does a loop in VB .NET cna have significant speed differernces. For example: dim therows() as datarow ..... dim row as datarow for each row in therows ........
3
by: creator_bob | last post by:
How do I create an array of datarows from a sorted list? I put a bunch of datarows into a sorted list to sort them. Then I got an array of the sorted elements. However, I cannot typecast them. ...
0
jas16183
by: jas16183 | last post by:
Hi Guys, need some help here, Im working on a project in vb.net, the problem im facing is that my tableadapter.update(dataset.datatable) is not functioning, the datatable has a relation with...
8
by: jehugaleahsa | last post by:
Hello: We wrote an entire application where we add our DataRows to our DataTables immediately. However, we have to shut off our constraints to do this. We would like to use detached DataRows to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.