Pedro Rainho

The important thing is never to stop questioning
posts - 118, comments - 55, trackbacks - 6

ADO.net Vs Linq to SQL - Conclusion

A few days ago I posted some tests comparing ADO.Net and Linq to SQL. As expected Linq to SQL is worst that ADO.Net, but as could be seen in some tests the values were very approximated.

In one of the post I had received a comment saying that I should do this:

IEnumerable<PerformanceTestTable> resultQuery = (from p in db.PerformanceTestTables
select p).ToList();

 

instead of this:

 

IQueryable<PerformanceTestTable> resultQuery = from p in db.PerformanceTestTables
select p;

 

and that "Using ToList (or any of the four extensions which call GetEnumerator), will force LINQ to get all the records at once. You should see a performance gain after adding ToList()."

 

I had done the tests and most are best using ToList(). This was the results:

 

Direct Single Select

previous test results

image

ADO.Net ADO.Net Linq to SQL Linq to SQL

AVERAGE

MEDIAN

AVERAGE

MEDIAN

469,8076

466

2747,09

2710

ToList() test results

image

 

ADO.Net ADO.Net Linq to SQL Linq to SQL

AVERAGE

MEDIAN

AVERAGE

MEDIAN

469,8076

466

2759,952

2719

 

Direct Select All 

previous test results

image

 

ADO.Net ADO.Net Linq to SQL Linq to SQL

AVERAGE

MEDIAN

AVERAGE

MEDIAN

2788,928

2733

5476,776

5494

 

ToList() test results

image

 

ADO.Net ADO.Net Linq to SQL Linq to SQL

AVERAGE

MEDIAN

AVERAGE

MEDIAN

2788,928

2733

5250,138

5112

 

Direct Select All 

previous test results

image

 

ADO.Net ADO.Net Linq to SQL Linq to SQL

AVERAGE

MEDIAN

AVERAGE

MEDIAN

964660,4

960886

1719343

1716473

 

ToList() test results

image

ADO.Net ADO.Net Linq to SQL Linq to SQL

AVERAGE

MEDIAN

AVERAGE

MEDIAN

964660,4

960886

1710777

1713680

Another test that I had done lately in order to understand why I get such different results using Linq to SQL I was able to see that the object DataContext takes lot's of ticks just to be initialized.

 

AVERAGE

MEDIAN

147,1824

137

 

One other conclusion that I had take from these tests was that if I want to get similar result, between ADO.Net and Linq to SQL, I had to use Store Procedures.

Print | posted on Friday, July 11, 2008 3:36 PM

Feedback

# re: ADO.net Vs Linq to SQL - Conclusion

Hi,

create a Singleton instance of DataContext may save a lot of time. Have tried CompiledQuery.Compile
instead?

Thanks,
Michael
8/4/2008 6:32 AM |

# re: ADO.net Vs Linq to SQL - Conclusion

In all of these tests I want every test to be unique this means i had to create all objects in order to do a test. This way I was able to measure how much ticks do I need just to execute my query. Of course I could only create one instance of dataContext and use it but i would also need to do the same to ado.net objects.

Haven't tried the CompiledQuery.Compile but I can try it in the weekend...

Pedro Rainho
8/4/2008 6:52 AM | Pedro Rainho
Gravatar

# re: ADO.net Vs Linq to SQL - Conclusion

Nice post Pedro. I've been experiencing similar results in my projects and finally decided to continue using ADO.NET at least until Microsoft releases a couple of service packs to improve the performance of LINQ to SQL and Entities. I'm not sure if these technologies are going to be widely adopted with the current performance issues and extra complexity. I have posted some alternative patterns for using ADO.NET more effectively at http://blogs.conatural.com, and the performance is comparable to native ADO, but I will use your examples to rerun the tests.

Thanks

RT.
12/23/2008 3:42 PM | Roger Torres

Post Comment

Title  
Name  
Email
Url
Comment   

Powered by: