Given a simple test:
Using Dapper:
for (int i = 0; i < 10000; i++)
{
Connection.Execute("UPDATE User SET Name = 'Max'");
}
The duration of this operation is as follows measured with a StopWatch
:
RunTime 00:00:37.51 Duration: 00:00:37.5150734 Duration in Milli seconds: 37515
Using Dapper plus:
User user = new User();
user.Name = "Max";
DapperPlusManager.Entity<User>().Table("User");
for (int i = 0; i < 10000; i++)
{
Connection.BulkUpdate(user);
}
The duration of this operation is as follows measured with a StopWatch
:
RunTime 00:00:39.85 Duration: 00:00:39.8553959 Duration in Milli seconds: 39855
I did this test in different scenarios and Dapper is always faster than Dapper plus
The question is clear, why is Dapper faster than Dapper Plus? What can cause such a thing?
Note: i'm using Sqlite with entity framework
why is Dapper faster than Dapper Plus? What can cause such a thing?
a) BulkUpdate
, as its name implies, is for bulk updates (i.e. updating multiple rows at once). You are calling it one at a time. You want to do a single call to it, not 10,000, to get the benefits.
b) The latter code likely needs reflection (e.g. to realise that there is a Name
property) in a way that the former code doesn't. That will incur some performance cost.
Fixing a) is almost certainly what you need to do. Also, use a more meaningful test whereby you are updating 10,000 different rows - not the same row 10,000 times (since with your current code the simplest fix is to have it execute just once rather than 10,000 times - but I suspect that is not what you want).