Why is EF Core 3.1.1 slower than EF Core 2.2.6?
See original GitHub issueSave 1 record EF Core 2.2.6 Run 1: 96.6822ms. Run 2: 2.1267ms. Run 3: 1.6975ms. EF Core 3.1.1 Run 1: 267.0279ms. Run 2: 7.1322ms. Run 3: 4.0974ms.
Retrieve 1 record EF Core 2.2.6 Run 1: 0.0218ms. Run 2: 0.024ms. Run 3: 0.0123ms. EF Core 3.1.1 Run 1: 0.0729ms. Run 2: 0.0204ms. Run 3: 0.0167ms.
Save 10,000 records EF Core 2.2.6 Run 1: 202.2927ms. Run 2: 58.1302ms. Run 3: 50.2324ms. EF Core 3.1.1 Run 1: 825.3337ms. Run 2: 207.5495ms. Run 3: 216.0945ms.
Retrieve 10,001 records EF Core 2.2.6 Run 1: 0.0266ms. Run 2: 0.0302ms. Run 3: 0.0503ms. EF Core 3.1.1 Run 1: 0.0273ms. Run 2: 0.0302ms. Run 3: 0.0754ms.
Stopwatch sw = new Stopwatch();
string s1 = "";
string s2 = "";
string s3 = "";
string s4 = "";
for (int j = 1; j <= 3; j++)
{
// Add 1 record
sw.Reset();
sw.Start();
TestHeader o = new TestHeader()
{
Name = $"Tester"
};
TestContext db = new TestContext();
db.Add(o);
db.SaveChanges();
sw.Stop();
TimeSpan ts = sw.Elapsed;
s1 += $"Run {j}: {ts.TotalMilliseconds.ToString()}ms. ";
// Retrieve 1 record
sw.Reset();
sw.Start();
db = new TestContext();
var item = db.TestHeader;
sw.Stop();
ts = sw.Elapsed;
s2 += $"Run {j}: {ts.TotalMilliseconds.ToString()}ms. ";
// Add 10,000 records
sw.Reset();
sw.Start();
List<TestHeader> list = new List<TestHeader>();
for (int i = 0; i <= 10000; i++)
{
TestHeader user = new TestHeader()
{
Name = $"User {i}"
};
list.Add(user);
}
db = new TestContext();
db.BulkInsert(list);
sw.Stop();
ts = sw.Elapsed;
s3 += $"Run {j}: {ts.TotalMilliseconds.ToString()}ms. ";
// Retrieve 10,001 records
sw.Restart();
sw.Start();
db = new TestContext();
var s = db.TestHeader;
sw.Stop();
ts = sw.Elapsed;
s4 += $"Run {j}: {ts.TotalMilliseconds.ToString()}ms. ";
db.RemoveRange(s);
db.SaveChanges();
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Why EF Core 3.1.1 slower than EF Core 2.2.6? Do you ...
I tested by saving 10,000 records and retrieving 10,000 records. All are in new projects. No additional codes. EF Core 2.2.6: Save 10,000 ......
Read more >Upgrading Entity Framework Core 2.2 | by Łukasz Wiśniewski
It is not obvious why is the EF Core 3.1 significantly slower than 3 queries in this case.
Read more >Entity Framework Core 3.1 Bug vs 2.2, Speed and Memory ...
EF 3.1.8 is never faster than 80ms and six requests take more than 100ms. Overall Elapsed -. EF 2.2.6 returns most requests in...
Read more >Your honest opinion on EF Core? : r/dotnet
So while EF Core is much faster than EF 6, it's still going to be slower than data access designed by someone who...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Alright, looks not so much difference. Thanks. How to use milliseconds instead of nanoseconds?
[EDITED. Changed ns to ms. Thanks @roji ] EFCore 2.2.6
EFCore 3.1.1
@sgtagan your benchmark is problematic in various ways. There is no warm-up phase, meaning that you include various start-up costs in your benchmark (e.g. query compilation). Unless I’m missing something you’re also only running each scenario once, which doesn’t provide much certainty as to the results.
I’d suggest you take a look at BenchmarkDotNet, which is a superb library which takes care of all the common pitfalls of benchmarking. It’s really easy to start with and provides very reliable results. If you have a BDN scenario which performs much worse on 3.1, please post the full benchmark code for that and we’ll look into it.
@AndriySvyryd could you post the benchmark code?