Previous Thread:   Performance Monitor Not Logging .Net CLR Counters?!?

4/11/2006 10:27:52 PM    DataReader Performance: Is it a myth?
I created a simple test scenario that compared the performance of a  
  
DataReader vs. a strongly typed DataTable. It seems that it is indeed  
  
quicker to traverse the result set when using the DataReader, but once you  
  
try to read the actual columns of the data, you lose all the benefits.  
  
When you have to make double method calls like:  
  
string strval = dr.GetString(dr.GetOrdinal("somecolumn"));  
  
just to read a single column value, it stands to reason that it's less  
  
efficient than:  
  
string strval = dataTable[i].somecolumn;  
  
In my tests, I found that if you have to read more than two columns of the  
  
row, the speed was about the same as using the strongly typed DataTable.  
  
Beyond that, the DataTable was more efficient.  
  
I also ran a similar test by binding the DataReader to an ASP.NET GridView  
  
server control, and it was no faster at rendering than when using a  
  
DataTable.  
  
I understand that the DataReader takes less overhead and theoretically  
  
should be faster than a strongly typed DataTable, but I don't see the  
  
benefit in a real-world situation. When you're actually doing something with  
  
that data.  
  
So am I missing something?



4/11/2006 11:15:26 PM    Re: DataReader Performance: Is it a myth?
"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message  
  
news:MPG.1ea6421cf6370d6a98d093@msnews.microsoft.com...  
  
Good point. The only issue then is how deep within the call stack the actual  
  
code that calls GetString() is compared to where the GetOrdinal() calls are  
  
made. You'd either have to store these values as members of a class or you'd  
  
have to pass these values as parameters if the GetString() calls are made in  
  
a separate method that is called from the main loop.

4/11/2006 11:46:36 PM    Re: DataReader Performance: Is it a myth?
Fred Taylor <freddyt@yahoo.com> wrote:  
  
<snip>  
  
One thing you may be missing is the ability to call GetOrdinal() *once*  
  
at the start of the fetch - then just call dr.GetString(cachedOrdinal).  
  
You don't need to recompute the ordinal for each row.  
  
--  
  
Jon Skeet - <skeet@pobox.com>  
  
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet  
  
If replying to the group, please do not mail me too