Julie Lerman's DevLife

DevLife Part I [May 2005 - March 2007]

My Links

Blog Stats

News

A blog for DevSource.com.

This blog was originally part of the blogs.ziffdavis.com site from May 2005 through June 2007 when the blog was moved to the Movable Type blog engine and hosted at blog.devsource.com/devlife.
The original blog was eventually shut down and I was given the posts so that I could host them on my own site.


Archives

ADO.NET Versions and Indexing

I had this question arrive through the “contact“ form of this blog:

How we can find out which version of ADO.NET  is present in our machine?

Is Indexing in Datatable available in Ado.NET 2.0?

ADO.NET is part of the .NET Framework and therefore you have whatever version(s) of ADO.NET as you do of the framework.

If you are programming in .NET 1.1 you will be using ADO.NET 1.1 and its functionality.

DataSet/DataTable Indexing exists since .NET 1.0. However in .NET 2.0 it has been rewritten from the ground up. A great way to see this in action is to watch how long it takes to add rows to a DataTable.

I tweaked the little example from Jackie Goldstein's DataSet Features article on MSDN Online where he adds one million rows to a DataTable with only one index on it. I added a counter that displays the elapsed time between every 10,000 records added. In VS2003, the time for each 10,000 records gets slower and slower and slower for every single interval. The first interval is 17 milliseconds. By the time we have 250,000 records in there, it takes over 4 full seconds to add the next 10,000 records. The total time for the loading is nearly 15 minutes on my computer. The CPU was pushed to 100% the entire time.

The same test in VS2005 shows the ADO.NET just flying through the inserts with no noticeable increase in time for each interval as the DataTable rows collection gets larger and larger. (Note that it is on a different machine with about the same speed but only 1/2 the memory.)The entire test takes about 19 seconds. Each increment of 10,000 took less than 250 milliseconds.

  

The difference? ADO.NET 1.x, indexing is performed on the entire DataTable, so the index is first only handling 10,000 records but then must process more and more and more. ADO.NET 2.0 indexes incrementally so it's only having to deal with a little chunk at a time which is why the index doesn't get bogged down as the DataTable fills up. It is a very impressive demonstration and helps me to better understand a bit of what's going on under the covers which helps in deciding how best to leverage this power.

posted on Thursday, March 16, 2006 9:07 AM