Created
May 2, 2024 16:46
-
-
Save sa-es-ir/75d679ce28404650e9ee60430300161a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using BenchmarkDotNet.Attributes; | |
| using BenchmarkDotNet.Columns; | |
| using BenchmarkDotNet.Configs; | |
| using BenchmarkDotNet.Reports; | |
| using EFQueryOptimization.Context; | |
| using EFQueryOptimization.Entities; | |
| using Microsoft.EntityFrameworkCore; | |
| namespace EFQueryOptimization; | |
| [Config(typeof(Config))] | |
| [HideColumns(Column.RatioSD, Column.AllocRatio)] | |
| [MemoryDiagnoser(false)] | |
| public class EFNoTrackingBenchmark | |
| { | |
| private class Config : ManualConfig | |
| { | |
| public Config() | |
| { | |
| SummaryStyle = SummaryStyle.Default.WithRatioStyle(RatioStyle.Trend); | |
| } | |
| } | |
| [Benchmark(Baseline = true)] | |
| public List<Role> Tracking() | |
| { | |
| var context = new ApplicationDbContext(); | |
| return context.Roles | |
| .Include(x => x.UserRoles) | |
| .ThenInclude(x => x.User) | |
| .Take(10) | |
| .ToList(); | |
| } | |
| [Benchmark] | |
| public List<Role> NoTracking() | |
| { | |
| var context = new ApplicationDbContext(); | |
| return context.Roles | |
| .Include(x => x.UserRoles) | |
| .ThenInclude(x => x.User) | |
| .AsNoTracking() | |
| .Take(10) | |
| .ToList(); | |
| } | |
| [Benchmark] | |
| public List<Role> NoTrackingWithIdentityResolution() | |
| { | |
| var context = new ApplicationDbContext(); | |
| return context.Roles | |
| .Include(x => x.UserRoles) | |
| .ThenInclude(x => x.User) | |
| .AsNoTrackingWithIdentityResolution() | |
| .Take(10) | |
| .ToList(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment