Entity Framework Core 2 Vs Dapper Performance Benchmark
Originally published on mmohsin.com.
Okay, i know that you have seen other benchmarks on the internet showing dapper is faster than Entity Framework. I found it unfair to compare an auto-generated SQL to the one written by a good developer, so decided to benchmark it on equal basis.
You can download the source code from git.
- A SQL database server which is on LAN
- A table containing 500k rows and 50 columns.
- .Net Core 2 Console Application.
- Fetching 5000 rows out of 500k rows.
Dapper’s query looks like this.
public class DapperRepository
public List GetUsersWithDapper()
using (IDbConnection db = new SqlConnection(@"YourConnectionString"))
($"select top 5000 * from users_general").ToList();
Entity Framework Core 2 Repository
public class EFRepository
public List GetUsersWithEF()
using (var db = new EFCore2TestContext())
return db.UsersGeneral.FromSql("Select top 5000 * from users_general").AsNoTracking().ToList();
Notice that i used AsNoTracking() for performance hit. As it will indicate EF not to track the models for change.
public class EFCore2VsDapper
_EFRepo = new EFRepository();
_DapperRepo = new DapperRepository();
_adoRepository = new ADORepository();
public List GetUsersWithEntityFramework() => _EFRepo.GetUsersWithEF();
public List GetUsersWithDapper() => _DapperRepo.GetUsersWithDapper();
//[Benchmark] Uncomment if you want to add ADO.NET to the competition
//public List GetUsersWithADO() => _adoRepository.GetUsersWithADO();
static void Main(string args)
var summary = BenchmarkRunner.Run(typeof(EFCore2VsDapper));
For fetching 5000 rows out of 500k, Entity Framework Core 2 outperformed dapper. It was hard for me to believe it initially so i ran the test several times. Same results.
Above results doesn’t mean that one is better in performance than the other, the above test was run for a very specific use case i-e fetching rows, passing plain query and using AsNoTracking(). Things can change for insert, update and especially when the EF context grows.
So, don’t select either based on my benchmark. You can download the source code and it is highly recommended to test it yourself for different scenarios before making a decision.
I’m missing something? or your tests gave different results? let me know by sharing your valuable feedback.