Added compatiblity mode

This commit is contained in:
Koen Bekkenutte
2021-06-03 04:46:25 +08:00
parent 898909660c
commit 11582d467c
9 changed files with 249 additions and 75 deletions
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using EntityFrameworkCore.Projectables.Extensions;
using EntityFrameworkCore.Projectables.Infrastructure;
namespace EntityFrameworkCore.Projectables.Benchmarks.Helpers
{
class TestDbContext : DbContext
{
readonly bool _useProjectables;
readonly bool _useFullCompatibiltyMode;
public TestDbContext(bool useProjectables, bool useFullCompatibiltyMode = true)
{
_useProjectables = useProjectables;
_useFullCompatibiltyMode = useFullCompatibiltyMode;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=ReadmeSample;Trusted_Connection=True");
if (_useProjectables)
{
optionsBuilder.UseProjectables(projectableOptions => {
projectableOptions.CompatibilityMode(_useFullCompatibiltyMode ? CompatibilityMode.Full : CompatibilityMode.Limited);
});
}
}
public DbSet<TestEntity> Entities => Set<TestEntity>();
}
}
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkCore.Projectables.Benchmarks.Helpers
{
public class TestEntity
{
public int Id { get; set; }
[Projectable]
public int IdPlus1 => Id + 1;
}
}
@@ -1,40 +1,16 @@
using System;
using System.IO.Compression;
using System.Linq;
using BenchmarkDotNet.Attributes;
using EntityFrameworkCore.Projectables.Benchmarks.Helpers;
using EntityFrameworkCore.Projectables.Extensions;
using EntityFrameworkCore.Projectables.Infrastructure;
using Microsoft.EntityFrameworkCore;
namespace EntityFrameworkCore.Projectables.Benchmarks
{
public class PlainOverhead
{
class TestEntity
{
public int Id { get; set; }
}
class TestDbContext : DbContext
{
readonly bool _useProjectables;
public TestDbContext(bool useProjectables)
{
_useProjectables = useProjectables;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=ReadmeSample;Trusted_Connection=True");
if (_useProjectables)
{
optionsBuilder.UseProjectables();
}
}
public DbSet<TestEntity> Entities => Set<TestEntity>();
}
[Benchmark(Baseline = true)]
public void WithoutProjectables()
{
@@ -47,7 +23,7 @@ namespace EntityFrameworkCore.Projectables.Benchmarks
}
[Benchmark]
public void WithProjectables()
public void WithProjectablesWithFullCompatibility()
{
using var dbContext = new TestDbContext(true);
@@ -57,5 +33,17 @@ namespace EntityFrameworkCore.Projectables.Benchmarks
}
}
[Benchmark]
public void WithProjectablesWithLimitedCompatibility()
{
using var dbContext = new TestDbContext(true, false);
for (int i = 0; i < 10000; i++)
{
dbContext.Entities.Select(x => x.Id).ToQueryString();
}
}
}
}
@@ -1,43 +1,15 @@
using System;
using System.Linq;
using BenchmarkDotNet.Attributes;
using EntityFrameworkCore.Projectables.Benchmarks.Helpers;
using EntityFrameworkCore.Projectables.Extensions;
using EntityFrameworkCore.Projectables.Infrastructure;
using Microsoft.EntityFrameworkCore;
namespace EntityFrameworkCore.Projectables.Benchmarks
{
public class ProjectableProperties
{
public class TestEntity
{
public int Id { get; set; }
[Projectable]
public int IdPlus1 => Id + 1;
}
class TestDbContext : DbContext
{
readonly bool _useProjectables;
public TestDbContext(bool useProjectables)
{
_useProjectables = useProjectables;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=ReadmeSample;Trusted_Connection=True");
if (_useProjectables)
{
optionsBuilder.UseProjectables();
}
}
public DbSet<TestEntity> Entities => Set<TestEntity>();
}
[Benchmark(Baseline = true)]
public void WithoutProjectables()
{
@@ -50,7 +22,7 @@ namespace EntityFrameworkCore.Projectables.Benchmarks
}
[Benchmark]
public void WithProjectables()
public void WithProjectablesWithFullCompatibility()
{
using var dbContext = new TestDbContext(true);
@@ -60,5 +32,15 @@ namespace EntityFrameworkCore.Projectables.Benchmarks
}
}
[Benchmark]
public void WithProjectablesWithLimitedCompatibility()
{
using var dbContext = new TestDbContext(true, false);
for (int i = 0; i < 10000; i++)
{
dbContext.Entities.Select(x => x.IdPlus1).ToQueryString();
}
}
}
}