mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2025-12-06 05:56:10 +00:00
Added a basic benchmark
This commit is contained in:
@@ -29,7 +29,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkCore.Project
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkCore.Projectables.FunctionalTests", "tests\EntityFrameworkCore.Projectables.FunctionalTests\EntityFrameworkCore.Projectables.FunctionalTests.csproj", "{A36F5471-0C16-4453-811B-818326931313}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReadmeSample", "samples\ReadmeSample\ReadmeSample.csproj", "{6F63E04C-9267-4211-8AC7-290C60331D60}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReadmeSample", "samples\ReadmeSample\ReadmeSample.csproj", "{6F63E04C-9267-4211-8AC7-290C60331D60}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{D1DB50EE-D639-46B0-8966-D0AA5F569620}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.Projectables.Benchmarks", "benchmarks\EntityFrameworkCore.Projectables.Benchmarks\EntityFrameworkCore.Projectables.Benchmarks.csproj", "{F2F01B61-5FB8-4F96-A6DE-824C9756B365}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -69,6 +73,10 @@ Global
|
||||
{6F63E04C-9267-4211-8AC7-290C60331D60}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6F63E04C-9267-4211-8AC7-290C60331D60}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6F63E04C-9267-4211-8AC7-290C60331D60}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F2F01B61-5FB8-4F96-A6DE-824C9756B365}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F2F01B61-5FB8-4F96-A6DE-824C9756B365}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F2F01B61-5FB8-4F96-A6DE-824C9756B365}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F2F01B61-5FB8-4F96-A6DE-824C9756B365}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -82,6 +90,7 @@ Global
|
||||
{2F0DD7D7-867F-4478-9E22-45C114B61C46} = {F5E4436F-87F2-46AB-A9EB-59B4BF21BF7A}
|
||||
{A36F5471-0C16-4453-811B-818326931313} = {F5E4436F-87F2-46AB-A9EB-59B4BF21BF7A}
|
||||
{6F63E04C-9267-4211-8AC7-290C60331D60} = {07584D01-2D30-404B-B0D1-32080C0CC18A}
|
||||
{F2F01B61-5FB8-4F96-A6DE-824C9756B365} = {D1DB50EE-D639-46B0-8966-D0AA5F569620}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {D17BD356-592C-4628-9D81-A04E24FF02F3}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.13.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\EntityFrameworkCore.Projectables.Generator\EntityFrameworkCore.Projectables.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="..\..\src\EntityFrameworkCore.Projectables\EntityFrameworkCore.Projectables.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using EntityFrameworkCore.Projectables.Extensions;
|
||||
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()
|
||||
{
|
||||
using var dbContext = new TestDbContext(false);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.Id).ToQueryString();
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void WithProjectables()
|
||||
{
|
||||
using var dbContext = new TestDbContext(true);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.Id).ToQueryString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Running;
|
||||
using EntityFrameworkCore.Projectables.Benchmarks;
|
||||
|
||||
BenchmarkSwitcher.FromAssembly(typeof(PlainOverhead).Assembly).Run(args, DefaultConfig.Instance.WithOption(ConfigOptions.DisableOptimizationsValidator, true));
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using EntityFrameworkCore.Projectables.Extensions;
|
||||
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()
|
||||
{
|
||||
using var dbContext = new TestDbContext(false);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.Id + 1).ToQueryString();
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void WithProjectables()
|
||||
{
|
||||
using var dbContext = new TestDbContext(true);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.IdPlus1).ToQueryString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user