Skip to content

Commit

Permalink
Remove cold start benchmarking (#20816)
Browse files Browse the repository at this point in the history
Closes #19879
  • Loading branch information
roji committed May 2, 2020
1 parent 1056a33 commit d00c9c5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 140 deletions.

This file was deleted.

75 changes: 33 additions & 42 deletions benchmark/EFCore.Benchmarks/Initialization/InitializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,61 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.ComponentModel;
using System.Linq;
using BenchmarkDotNet.Attributes;
using Microsoft.EntityFrameworkCore.Benchmarks.Models.AdventureWorks;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;

namespace Microsoft.EntityFrameworkCore.Benchmarks.Initialization
{
[DisplayName("InitializationTests")]
public abstract class InitializationTests<T>
where T : ColdStartEnabledTests, new()
public abstract class InitializationTests
{
#if NET461
private ColdStartSandbox _sandbox;
#endif
private ColdStartEnabledTests _testClass;

#if NET461
[Params(true, false)]
#elif NETCOREAPP2_0 || NETCOREAPP2_1
[Params(false)]
#endif
public bool Cold { get; set; }

[GlobalSetup]
public virtual void Initialize()
{
if (Cold)
{
#if NET461
_sandbox = new ColdStartSandbox();
_testClass = _sandbox.CreateInstance<T>();
#endif
}
else
{
_testClass = new T();
}
}

#if NET461
[GlobalCleanup]
public virtual void CleanupContext()
{
_sandbox?.Dispose();
}
#endif
protected abstract AdventureWorksContextBase CreateContext();
protected abstract ConventionSet CreateConventionSet();

[Benchmark]
public virtual void CreateAndDisposeUnusedContext()
{
_testClass.CreateAndDisposeUnusedContext(Cold ? 1 : 10000);
for (var i = 0; i < 10000; i++)
{
// ReSharper disable once UnusedVariable
using (var context = CreateContext())
{
}
}
}

[Benchmark]
public virtual void InitializeAndQuery_AdventureWorks()
{
_testClass.InitializeAndQuery_AdventureWorks(Cold ? 1 : 1000);
for (var i = 0; i < 1000; i++)
{
using (var context = CreateContext())
{
_ = context.Department.First();
}
}
}

[Benchmark]
public virtual void InitializeAndSaveChanges_AdventureWorks()
{
_testClass.InitializeAndSaveChanges_AdventureWorks(Cold ? 1 : 100);
for (var i = 0; i < 100; i++)
{
using (var context = CreateContext())
{
context.Currency.Add(
new Currency { CurrencyCode = "TMP", Name = "Temporary" });

using (context.Database.BeginTransaction())
{
context.SaveChanges();

// TODO: Don't measure transaction rollback
}
}
}
}

[Benchmark]
Expand All @@ -75,7 +68,5 @@ public virtual void BuildModel_AdventureWorks()
// ReSharper disable once UnusedVariable
var model = builder.Model;
}

protected abstract ConventionSet CreateConventionSet();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// 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.Models.AdventureWorks;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;

namespace Microsoft.EntityFrameworkCore.Benchmarks.Initialization
{
public class InitializationSqlServerTests : InitializationTests<ColdStartEnabledSqlServerTest>
public class InitializationSqlServerTests : InitializationTests
{
protected override ConventionSet CreateConventionSet()
{
return SqlServerConventionSetBuilder.Build();
}
protected override AdventureWorksContextBase CreateContext() => AdventureWorksSqlServerFixture.CreateContext();
protected override ConventionSet CreateConventionSet() => SqlServerConventionSetBuilder.Build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// 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.Models.AdventureWorks;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;

namespace Microsoft.EntityFrameworkCore.Benchmarks.Initialization
{
public class InitializationSqliteTests : InitializationTests<ColdStartEnabledSqliteTest>
public class InitializationSqliteTests : InitializationTests
{
protected override ConventionSet CreateConventionSet()
{
return SqliteConventionSetBuilder.Build();
}
protected override AdventureWorksContextBase CreateContext()=> AdventureWorksSqliteFixture.CreateContext();
protected override ConventionSet CreateConventionSet() => SqliteConventionSetBuilder.Build();
}
}

0 comments on commit d00c9c5

Please sign in to comment.