using BenchmarkDotNet.Attributes; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; namespace Api; [MemoryDiagnoser] public class SplitQueryBenchmarks { private const string ConnectionString = "Host=127.0.0.1;Port=5438;Database=orders;Username=mnw220;Password=mnw220"; private static readonly DateTime From = Seeder.FirstDay.AddDays(10); private static readonly DateTime To = From.AddDays(3); private PooledDbContextFactory _factory = null!; [GlobalSetup] public void Setup() => _factory = new PooledDbContextFactory( new DbContextOptionsBuilder().UseNpgsql(ConnectionString).Options); [Benchmark] public async Task Page() { await using var db = _factory.CreateDbContext(); var orders = await OrderQueries.PageAsync(db, customerId: 42, page: 0, CancellationToken.None); return orders.Count; } [Benchmark] public async Task Report() { await using var db = _factory.CreateDbContext(); var orders = await OrderQueries.RangeAsync(db, From, To, CancellationToken.None); return orders.Count; } [Benchmark] public async Task PageFourReferences() { await using var db = _factory.CreateDbContext(); var orders = await OrderQueries.PageWithReferencesAsync(db, customerId: 42, page: 0, CancellationToken.None); return orders.Count; } [Benchmark] public async Task ReportFourReferences() { await using var db = _factory.CreateDbContext(); var orders = await OrderQueries.RangeWithReferencesAsync(db, From, To, CancellationToken.None); return orders.Count; } }