Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge benchmarks back into main repo #7757

Merged
merged 1 commit into from Mar 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion EntityFramework.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26220.0
VisualStudioVersion = 15.0.26214.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.EntityFrameworkCore", "src\Microsoft.EntityFrameworkCore\Microsoft.EntityFrameworkCore.csproj", "{715C38E9-B2F5-4DB2-8025-0C6492DEBDD4}"
EndProject
Expand Down Expand Up @@ -63,6 +63,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.EntityFrameworkCo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.EntityFrameworkCore.Sqlite", "src\Microsoft.EntityFrameworkCore.Sqlite\Microsoft.EntityFrameworkCore.Sqlite.csproj", "{6FF0B963-0544-4428-8AE1-5A71872B55AD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.EntityFrameworkCore.Benchmarks", "test\Microsoft.EntityFrameworkCore.Benchmarks\Microsoft.EntityFrameworkCore.Benchmarks.csproj", "{E3146D04-6E87-41C1-A2E3-F2D7CDFB9B99}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.EntityFrameworkCore.Benchmarks.EFCore", "test\Microsoft.EntityFrameworkCore.Benchmarks.EFCore\Microsoft.EntityFrameworkCore.Benchmarks.EFCore.csproj", "{049A9748-B3CE-4412-B455-F7108B3BA239}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.EntityFrameworkCore.Benchmarks.EF6", "test\Microsoft.EntityFrameworkCore.Benchmarks.EF6\Microsoft.EntityFrameworkCore.Benchmarks.EF6.csproj", "{477EBF1E-A4B8-4D60-8681-5D6D5BB42CE1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -181,6 +187,18 @@ Global
{6FF0B963-0544-4428-8AE1-5A71872B55AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FF0B963-0544-4428-8AE1-5A71872B55AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FF0B963-0544-4428-8AE1-5A71872B55AD}.Release|Any CPU.Build.0 = Release|Any CPU
{E3146D04-6E87-41C1-A2E3-F2D7CDFB9B99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3146D04-6E87-41C1-A2E3-F2D7CDFB9B99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3146D04-6E87-41C1-A2E3-F2D7CDFB9B99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3146D04-6E87-41C1-A2E3-F2D7CDFB9B99}.Release|Any CPU.Build.0 = Release|Any CPU
{049A9748-B3CE-4412-B455-F7108B3BA239}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{049A9748-B3CE-4412-B455-F7108B3BA239}.Debug|Any CPU.Build.0 = Debug|Any CPU
{049A9748-B3CE-4412-B455-F7108B3BA239}.Release|Any CPU.ActiveCfg = Release|Any CPU
{049A9748-B3CE-4412-B455-F7108B3BA239}.Release|Any CPU.Build.0 = Release|Any CPU
{477EBF1E-A4B8-4D60-8681-5D6D5BB42CE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{477EBF1E-A4B8-4D60-8681-5D6D5BB42CE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{477EBF1E-A4B8-4D60-8681-5D6D5BB42CE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{477EBF1E-A4B8-4D60-8681-5D6D5BB42CE1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -214,5 +232,8 @@ Global
{D3D0A8E8-EC2F-4E01-8650-8554E186A66F} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
{7583E3F0-8B29-4BEA-A55E-E8B66E6FD508} = {258D5057-81B9-40EC-A872-D21E27452749}
{6FF0B963-0544-4428-8AE1-5A71872B55AD} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
{E3146D04-6E87-41C1-A2E3-F2D7CDFB9B99} = {258D5057-81B9-40EC-A872-D21E27452749}
{049A9748-B3CE-4412-B455-F7108B3BA239} = {258D5057-81B9-40EC-A872-D21E27452749}
{477EBF1E-A4B8-4D60-8681-5D6D5BB42CE1} = {258D5057-81B9-40EC-A872-D21E27452749}
EndGlobalSection
EndGlobal
5 changes: 5 additions & 0 deletions build/repo.props
@@ -0,0 +1,5 @@
<Project>
<ItemGroup>
<ExcludeFromTest Include="$(RepositoryRoot)test\Microsoft.EntityFrameworkCore.Benchmarks.EF6\*.csproj" Condition="'$(OS)' != 'Windows_NT'" />
</ItemGroup>
</Project>
@@ -0,0 +1,157 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.EntityFrameworkCore.Benchmarks.EF6.Models.Orders;
using Xunit;

namespace Microsoft.EntityFrameworkCore.Benchmarks.EF6.ChangeTracker
{
[SqlServerRequired]
[SkipForNonBenchmarkTestRuns("Test takes a long time to execute, only run during benchmark collection runs.")]
public class DbSetOperationTests : IClassFixture<DbSetOperationTests.DbSetOperationFixture>
{
private readonly DbSetOperationFixture _fixture;

public DbSetOperationTests(DbSetOperationFixture fixture)
{
_fixture = fixture;
}

[Benchmark]
[BenchmarkVariation("AutoDetectChanges On", iterations: 1, data: new object[] { true })]
[BenchmarkVariation("AutoDetectChanges Off", false)]
public void Add(IMetricCollector collector, bool autoDetectChanges)
{
using (var context = _fixture.CreateContext())
{
context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

var customers = _fixture.CreateCustomers(20000, setPrimaryKeys: false);

using (collector.StartCollection())
{
foreach (var customer in customers)
{
context.Customers.Add(customer);
}
}
}
}

[Benchmark]
[BenchmarkVariation("AutoDetectChanges On", iterations: 1, data: new object[] { true })]
[BenchmarkVariation("AutoDetectChanges Off", false)]
public void AddRange(IMetricCollector collector, bool autoDetectChanges)
{
using (var context = _fixture.CreateContext())
{
context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

var customers = _fixture.CreateCustomers(20000, setPrimaryKeys: false);

using (collector.StartCollection())
{
context.Customers.AddRange(customers);
}
}
}

[Benchmark]
[BenchmarkVariation("AutoDetectChanges On", iterations: 1, data: new object[] { true })]
[BenchmarkVariation("AutoDetectChanges Off", false)]
public void Attach(IMetricCollector collector, bool autoDetectChanges)
{
using (var context = _fixture.CreateContext())
{
context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

var customers = _fixture.CreateCustomers(20000, setPrimaryKeys: true);

using (collector.StartCollection())
{
foreach (var customer in customers)
{
context.Customers.Attach(customer);
}
}
}
}

// Note: AttachRange() not implemented because there is no
// API for bulk attach in EF6.x

[Benchmark]
[BenchmarkVariation("AutoDetectChanges On", iterations: 1, data: new object[] { true })]
[BenchmarkVariation("AutoDetectChanges Off", false)]
public void Remove(IMetricCollector collector, bool autoDetectChanges)
{
using (var context = _fixture.CreateContext())
{
context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

var customers = _fixture.CreateCustomers(20000, setPrimaryKeys: true);
customers.ForEach(c => context.Customers.Attach(c));

using (collector.StartCollection())
{
foreach (var customer in customers)
{
context.Customers.Remove(customer);
}
}
}
}

[Benchmark]
[BenchmarkVariation("AutoDetectChanges On", iterations: 1, data: new object[] { true })]
[BenchmarkVariation("AutoDetectChanges Off", false)]
public void RemoveRange(IMetricCollector collector, bool autoDetectChanges)
{
using (var context = _fixture.CreateContext())
{
context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

var customers = _fixture.CreateCustomers(20000, setPrimaryKeys: true);
customers.ForEach(c => context.Customers.Attach(c));

using (collector.StartCollection())
{
context.Customers.RemoveRange(customers);
}
}
}

[Benchmark]
[BenchmarkVariation("AutoDetectChanges On", iterations: 1, data: new object[] { true })]
[BenchmarkVariation("AutoDetectChanges Off", false)]
public void Update(IMetricCollector collector, bool autoDetectChanges)
{
using (var context = _fixture.CreateContext())
{
context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

var customers = _fixture.CreateCustomers(20000, setPrimaryKeys: true);
customers.ForEach(c => context.Customers.Attach(c));

using (collector.StartCollection())
{
foreach (var customer in customers)
{
context.Entry(customer).State = System.Data.Entity.EntityState.Modified;
}
}
}
}

// Note: UpdateRange() not implemented because there is no
// API for bulk update in EF6.x

public class DbSetOperationFixture : OrdersFixture
{
public DbSetOperationFixture()
: base("Perf_ChangeTracker_DbSetOperation_EF6", 0, 0, 0, 0)
{
}
}
}
}
@@ -0,0 +1,148 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Linq;
using Microsoft.EntityFrameworkCore.Benchmarks.Models.Orders;
using Microsoft.EntityFrameworkCore.Benchmarks.EF6.Models.Orders;
using Xunit;

namespace Microsoft.EntityFrameworkCore.Benchmarks.EF6.ChangeTracker
{
[SqlServerRequired]
[SkipForNonBenchmarkTestRuns("Test takes a long time to execute, only run during benchmark collection runs.")]
public class FixupTests : IClassFixture<FixupTests.FixupFixture>
{
private readonly FixupFixture _fixture;

public FixupTests(FixupFixture fixture)
{
_fixture = fixture;
}

[Benchmark]
[BenchmarkVariation("AutoDetectChanges On", iterations: 1, data: new object[] { true })]
[BenchmarkVariation("AutoDetectChanges Off", false)]
public void AddChildren(IMetricCollector collector, bool autoDetectChanges)
{
using (var context = _fixture.CreateContext())
{
context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

var customers = _fixture.CreateCustomers(5000, setPrimaryKeys: true);
var orders = _fixture.CreateOrders(customers, ordersPerCustomer: 2, setPrimaryKeys: false);
customers.ForEach(c => context.Customers.Attach(c));

Assert.All(orders, o => Assert.Null(o.Customer));

using (collector.StartCollection())
{
foreach (var order in orders)
{
context.Orders.Add(order);
}
}

Assert.All(orders, o => Assert.NotNull(o.Customer));
}
}

// Note: AddParents() not implemented because fixup to added parents
// only happens during SaveChanges for EF6.x (not during Add)

[Benchmark]
[BenchmarkVariation("AutoDetectChanges On", iterations: 1, data: new object[] { true })]
[BenchmarkVariation("AutoDetectChanges Off", false)]
public void AttachChildren(IMetricCollector collector, bool autoDetectChanges)
{
using (var context = _fixture.CreateContext())
{
context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

var customers = _fixture.CreateCustomers(5000, setPrimaryKeys: true);
var orders = _fixture.CreateOrders(customers, ordersPerCustomer: 2, setPrimaryKeys: true);
customers.ForEach(c => context.Customers.Attach(c));

Assert.All(orders, o => Assert.Null(o.Customer));

using (collector.StartCollection())
{
foreach (var order in orders)
{
context.Orders.Attach(order);
}
}

Assert.All(orders, o => Assert.NotNull(o.Customer));
}
}

[Benchmark]
[BenchmarkVariation("AutoDetectChanges On", iterations: 1, data: new object[] { true })]
[BenchmarkVariation("AutoDetectChanges Off", false)]
public void AttachParents(IMetricCollector collector, bool autoDetectChanges)
{
using (var context = _fixture.CreateContext())
{
context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

var customers = _fixture.CreateCustomers(5000, setPrimaryKeys: true);
var orders = _fixture.CreateOrders(customers, ordersPerCustomer: 2, setPrimaryKeys: true);
orders.ForEach(o => context.Orders.Attach(o));

Assert.All(customers, c => Assert.Null(c.Orders));

using (collector.StartCollection())
{
foreach (var customer in customers)
{
context.Customers.Attach(customer);
}
}

Assert.All(customers, c => Assert.Equal(2, c.Orders.Count));
}
}

[Benchmark(Iterations = 1)]
public void QueryChildren(IMetricCollector collector)
{
using (var context = _fixture.CreateContext())
{
context.Customers.ToList();

collector.StartCollection();
var orders = context.Orders.ToList();
collector.StopCollection();

Assert.Equal(5000, context.ChangeTracker.Entries<Customer>().Count());
Assert.Equal(10000, context.ChangeTracker.Entries<Order>().Count());
Assert.All(orders, o => Assert.NotNull(o.Customer));
}
}

[Benchmark(Iterations = 1)]
public void QueryParents(IMetricCollector collector)
{
using (var context = _fixture.CreateContext())
{
context.Orders.ToList();

collector.StartCollection();
var customers = context.Customers.ToList();
collector.StopCollection();

Assert.Equal(5000, context.ChangeTracker.Entries<Customer>().Count());
Assert.Equal(10000, context.ChangeTracker.Entries<Order>().Count());
Assert.All(customers, c => Assert.Equal(2, c.Orders.Count));
}
}

public class FixupFixture : OrdersFixture
{
public FixupFixture()
: base("Perf_ChangeTracker_Fixup_EF6", 0, 5000, 2, 0)
{
}
}
}
}