Entity Framework 6.1.3 vs. Linq2SQL vs. NHibernate Smackdown!

Summary

I’ve done these ad-hoc ORM performance tests in the past.  In this test I’m going to re-test the latest Entity Framework (version 6.1.3) against the latest Linq-to-SQL version.  I’ll be using EF code-first this time to make sure there isn’t any extra overhead.  I’ll also be using Visual Studio 2013.

The Hardware and Software

This test was executed on an older PC with an Intel Core2 Duo CPU running at 3Ghz (E8400).  I’m using 8 Gigabytes of Ram and a solid-state hard drive.  This machine has Windows 10 (64 bit) and I’m using Visual Studio 2013 and Microsoft SQL Server 2014.

The Tests

I ran the tests 5 times each and chose the shortest time for each section (insert, update, delete and select).  I also added the NHibernate ORM just to make this a 3-way smack-down.  I performed the basic 4 CRUD operations (insert, update, select, delete) and compared results for each operation.

The Results

It appears that EF has been improved since the last time I’ve performed this test.  Entity Framework seems to be a bit faster than Linq-to-SQL this time.  However, NHibernate still outperforms both Entity Framework and Linq-to-SQL by a large margin (between 2x and almost 3x).

Here are the results:

Usual Disclaimer

I have to warn you that this experiment is unscientific.  I’m using a PC that I use for general purpose day-to-day operations.  What this means is that I have a virus checker and a backup program that can kick in at any time.  Not to mention the fact that I have automatic updates set to on.  To make this experiment more accurate, I would need to setup a stripped down PC and run comparison tests with no other programs running.  In other words, your results may vary.

So my advice is to download the source from this blog post, compile and run this test on your machine or the expected destination setup (i.e. against your company SQL server).  You can also increase the size of the data set to simulate your expected data volume.

Download the Code

You can go to my GitHub account by clicking here.  Download the zip file and unzip it to your visual studio project directory.  Don’t forget to search the code for the connection string (“My Connection String”) and replace with your own connection string.  This occurs in 3 files: SampleDataContext.cs, App.config and NHibernateSessionFactory.cs.

Leave a Reply