LINQ Vs Datatable.Select


The article which is in the below link points out using “select” (e.g. dtTest.Select("Col1  = ""xxx""")) on a DataTable can be really slow.


Snippet from the article:
"Select takes arbitrary criteria and returns an array of DataRows. Essentially, DataTable.Select has to walk the entire table and compare every record to the criteria that you passed in."

This article has compared LINQ with the DataTable.Select and the performance stats for LINQ look very impressive.  I think Microsoft has done a lot of optimization on LINQ.

To see the actual result in action I made a small sample which loads some junk rows to a DataTable and does selection by using DataTable.Select and LINQ

  

Test 1











  • Number of Rows      - 5000
  • DataTable.Select      - 9.34ms
  • LINQ                      - 1.07ms

Test 2











  • Number of Rows      - 500,000
  • DataTable.Select      - 1382.03ms = 1.4Sec
  • LINQ                      - 1.0858ms   = 0.001Sec 



VE FUN WITH CODING :-)