mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-05-23 19:25:45 +00:00
Refactored benchmark a bit
This commit is contained in:
@@ -12,5 +12,8 @@ namespace EntityFrameworkCore.Projectables.Benchmarks.Helpers
|
||||
|
||||
[Projectable]
|
||||
public int IdPlus1 => Id + 1;
|
||||
|
||||
[Projectable]
|
||||
public int IdPlus1Method() => Id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Benchmarks.Helpers
|
||||
{
|
||||
public static class TestEntityExtensions
|
||||
{
|
||||
public static int IdPlus1ExtensionMethod(this TestEntity entity) => entity.Id + 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using EntityFrameworkCore.Projectables.Benchmarks.Helpers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Benchmarks
|
||||
{
|
||||
public class ProjectableExtensionMethods
|
||||
{
|
||||
const int innerLoop = 10000;
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void WithoutProjectables()
|
||||
{
|
||||
using var dbContext = new TestDbContext(false);
|
||||
|
||||
for (int i = 0; i < innerLoop; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.Id + 1).ToQueryString();
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void WithProjectablesWithFullCompatibility()
|
||||
{
|
||||
using var dbContext = new TestDbContext(true);
|
||||
|
||||
for (int i = 0; i < innerLoop; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.IdPlus1Method()).ToQueryString();
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void WithProjectablesWithLimitedCompatibility()
|
||||
{
|
||||
using var dbContext = new TestDbContext(true, false);
|
||||
|
||||
for (int i = 0; i < innerLoop; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.IdPlus1Method()).ToQueryString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
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 ProjectableMethods
|
||||
{
|
||||
const int innerLoop = 10000;
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void WithoutProjectables()
|
||||
{
|
||||
using var dbContext = new TestDbContext(false);
|
||||
|
||||
for (int i = 0; i < innerLoop; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.Id + 1).ToQueryString();
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void WithProjectablesWithFullCompatibility()
|
||||
{
|
||||
using var dbContext = new TestDbContext(true);
|
||||
|
||||
for (int i = 0; i < innerLoop; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.IdPlus1Method()).ToQueryString();
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void WithProjectablesWithLimitedCompatibility()
|
||||
{
|
||||
using var dbContext = new TestDbContext(true, false);
|
||||
|
||||
for (int i = 0; i < innerLoop; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.IdPlus1Method()).ToQueryString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,17 @@ namespace EntityFrameworkCore.Projectables.Benchmarks
|
||||
{
|
||||
public class ProjectableProperties
|
||||
{
|
||||
const int innerLoop = 10000;
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void WithoutProjectables()
|
||||
{
|
||||
using var dbContext = new TestDbContext(false);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
for (int i = 0; i < innerLoop; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.Id + 1).ToQueryString();
|
||||
if (1 == i)
|
||||
throw new Exception(dbContext.Entities.Select(x => x.Id + 1).ToQueryString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +29,7 @@ namespace EntityFrameworkCore.Projectables.Benchmarks
|
||||
{
|
||||
using var dbContext = new TestDbContext(true);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
for (int i = 0; i < innerLoop; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.IdPlus1).ToQueryString();
|
||||
}
|
||||
@@ -37,7 +40,7 @@ namespace EntityFrameworkCore.Projectables.Benchmarks
|
||||
{
|
||||
using var dbContext = new TestDbContext(true, false);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
for (int i = 0; i < innerLoop; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.IdPlus1).ToQueryString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user