Home > Developing Using CodeFluent Entities > CodeFluent Entities Performance Comparison

CodeFluent Entities Performance Comparison


We often get questions on how CodeFluent Entities performs compared to other tools as LINQ to SQL, ADO.NET Entity Framework, or NHibernate.

We compared those technologies by writing simple console applications doing the same queries on the same Northwind database and running on the same machine. Here’s in pseudo code what each console application is doing:

Start timer
Iterate 100 times
   Load all orders from database
   Loop through loaded orders
End of iteration
Stop timer
Print elapsed time (ms)

You’ll find the solution used here so you can run/edit the tests yourself: PerformanceTests.zip

Technologies compared are:

  • CodeFluent Entities (Build 663 available here),
  • ADO.NET Entity Framework 4.0 (edmx version 2.0),
  • LINQ to SQL (.NET 4.0),
  • NHibernate 3.3,
  • Dapper-dot-net,
  • Handmade code using a SqlCommand, SqlDataReader (named SqlClient in the table below).

Tests use:

  • Visual Studio 2010 SP1,
  • .NET 4.0 (C#),
  • SQL Server 2008,
  • the Northwind database.

Results (in ms, sorted by performance results):

Technology #1 #2 #3 #4 #5 #6 #7 #8 #9 #10
SqlClient 516 524 517 518 519 524 515 518 520 520
Dapper 609 651 626 634 608 624 606 611 606 614
LINQ to SQL 765 763 775 753 749 760 763 756 767 764
CodeFluent Entities 946 960 936 944 946 965 931 950 932 954
NHibernate 2158 2123 2122 2174 2131 2212 2176 2161 2138 2200
Entity Framework 2435 2334 2327 2291 2371 2309 2283 2374 2431 2351

Averages:

  • SqlClient: 519ms
  • Dapper: 619ms
  • LINQ to SQL: 762ms
  • CodeFluent Entities: 946ms
  • NHibernate: 2151ms
  • ADO.NET Entity Framework: 2351ms

Without surprises SqlClient and Dapper performed faster as all they do is execute the query and map results to objects. Right after is LINQ to SQL losing a little time by handling relationships and so does CodeFluent Entities by handling in addition property changed events and default values (spares the developer the DbNull check for value types).

NHibernate and ADO.NET Entity Framework score last to this performance test for different reasons. NHibernate because it uses reflection to build a proxy of your classes to map database values to it. Entity Framework because we’re rebuilding a context at each iteration to ensure we’re loading all our orders from database (I tried doing a refresh on all orders but that’s even worse).

In this test we used CodeFluent Entities’ default values but in a following post we’ll see how to use CodeFluent Entities to perform as Dapper and LINQ to SQL as in particular scenarios, performance is more important than features.

Regards,

Carl Anderson

  1. FRENGUE
    November 19, 2012 at 3:40 pm

    Hello, Can you reexecute your test with context.Course.MergeOption = MergeOption.NoTracking; for Entityframework please ? (http://blogs.microsoft.co.il/blogs/gilf/archive/2009/02/20/disabling-change-tracking-in-entity-framework.aspx)

    • SoftFluent
      November 20, 2012 at 11:52 am

      Hello Frengue,
      there are many configurations possible for each scenarios depending on different contexts and the purpose of this post wasn’t to list them all. Therefore we used the default values.
      However, we provided the solution so you can make your own tests. I invite you to tweak the configuration according to your taste. Don’t hesitate to share your results with all of us! Thanks.

  1. June 5, 2012 at 5:09 pm
  2. June 10, 2013 at 3:08 pm
  3. June 10, 2013 at 3:12 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s