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,
- Handmade code using a SqlCommand, SqlDataReader (named SqlClient in the table below).
- Visual Studio 2010 SP1,
- .NET 4.0 (C#),
- SQL Server 2008,
- the Northwind database.
Results (in ms, sorted by performance results):
|LINQ to SQL||765||763||775||753||749||760||763||756||767||764|
- 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.