diff --git a/benchmark/EFCore.Benchmarks/Initialization/ColdStartEnabledTests.cs b/benchmark/EFCore.Benchmarks/Initialization/ColdStartEnabledTests.cs deleted file mode 100644 index b0bf1d24288..00000000000 --- a/benchmark/EFCore.Benchmarks/Initialization/ColdStartEnabledTests.cs +++ /dev/null @@ -1,58 +0,0 @@ -// 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; -using System.Linq; -using Microsoft.EntityFrameworkCore.Benchmarks.Models.AdventureWorks; - -// ReSharper disable InconsistentNaming - -namespace Microsoft.EntityFrameworkCore.Benchmarks.Initialization -{ - public abstract class ColdStartEnabledTests : MarshalByRefObject - { - protected abstract AdventureWorksContextBase CreateContext(); - - public void CreateAndDisposeUnusedContext(int count) - { - for (var i = 0; i < count; i++) - { - // ReSharper disable once UnusedVariable - using (var context = CreateContext()) - { - } - } - } - - public void InitializeAndQuery_AdventureWorks(int count) - { - for (var i = 0; i < count; i++) - { - using (var context = CreateContext()) - { - // ReSharper disable once ReturnValueOfPureMethodIsNotUsed - context.Department.First(); - } - } - } - - public void InitializeAndSaveChanges_AdventureWorks(int count) - { - for (var i = 0; i < count; 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 - } - } - } - } - } -} diff --git a/benchmark/EFCore.Benchmarks/Initialization/InitializationTests.cs b/benchmark/EFCore.Benchmarks/Initialization/InitializationTests.cs index c41636f5278..9aea42a52a6 100644 --- a/benchmark/EFCore.Benchmarks/Initialization/InitializationTests.cs +++ b/benchmark/EFCore.Benchmarks/Initialization/InitializationTests.cs @@ -2,6 +2,7 @@ // 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; @@ -9,61 +10,53 @@ namespace Microsoft.EntityFrameworkCore.Benchmarks.Initialization { [DisplayName("InitializationTests")] - public abstract class InitializationTests - 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(); -#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] @@ -75,7 +68,5 @@ public virtual void BuildModel_AdventureWorks() // ReSharper disable once UnusedVariable var model = builder.Model; } - - protected abstract ConventionSet CreateConventionSet(); } } diff --git a/benchmark/EFCore.SqlServer.Benchmarks/Initialization/ColdStartEnabledSqlServerTest.cs b/benchmark/EFCore.SqlServer.Benchmarks/Initialization/ColdStartEnabledSqlServerTest.cs deleted file mode 100644 index 512fba6759e..00000000000 --- a/benchmark/EFCore.SqlServer.Benchmarks/Initialization/ColdStartEnabledSqlServerTest.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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; - -namespace Microsoft.EntityFrameworkCore.Benchmarks.Initialization -{ - public class ColdStartEnabledSqlServerTest : ColdStartEnabledTests - { - protected override AdventureWorksContextBase CreateContext() - { - return AdventureWorksSqlServerFixture.CreateContext(); - } - } -} diff --git a/benchmark/EFCore.SqlServer.Benchmarks/Initialization/InitializationSqlServerTests.cs b/benchmark/EFCore.SqlServer.Benchmarks/Initialization/InitializationSqlServerTests.cs index cd395b5e5fa..373cd264465 100644 --- a/benchmark/EFCore.SqlServer.Benchmarks/Initialization/InitializationSqlServerTests.cs +++ b/benchmark/EFCore.SqlServer.Benchmarks/Initialization/InitializationSqlServerTests.cs @@ -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 + public class InitializationSqlServerTests : InitializationTests { - protected override ConventionSet CreateConventionSet() - { - return SqlServerConventionSetBuilder.Build(); - } + protected override AdventureWorksContextBase CreateContext() => AdventureWorksSqlServerFixture.CreateContext(); + protected override ConventionSet CreateConventionSet() => SqlServerConventionSetBuilder.Build(); } } diff --git a/benchmark/EFCore.Sqlite.Benchmarks/Initialization/ColdStartEnabledSqliteTest.cs b/benchmark/EFCore.Sqlite.Benchmarks/Initialization/ColdStartEnabledSqliteTest.cs deleted file mode 100644 index b4e5b8a63f1..00000000000 --- a/benchmark/EFCore.Sqlite.Benchmarks/Initialization/ColdStartEnabledSqliteTest.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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; - -namespace Microsoft.EntityFrameworkCore.Benchmarks.Initialization -{ - public class ColdStartEnabledSqliteTest : ColdStartEnabledTests - { - protected override AdventureWorksContextBase CreateContext() - { - return AdventureWorksSqliteFixture.CreateContext(); - } - } -} diff --git a/benchmark/EFCore.Sqlite.Benchmarks/Initialization/InitializationSqliteTests.cs b/benchmark/EFCore.Sqlite.Benchmarks/Initialization/InitializationSqliteTests.cs index a68303aa53b..3998146a8c6 100644 --- a/benchmark/EFCore.Sqlite.Benchmarks/Initialization/InitializationSqliteTests.cs +++ b/benchmark/EFCore.Sqlite.Benchmarks/Initialization/InitializationSqliteTests.cs @@ -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 + public class InitializationSqliteTests : InitializationTests { - protected override ConventionSet CreateConventionSet() - { - return SqliteConventionSetBuilder.Build(); - } + protected override AdventureWorksContextBase CreateContext()=> AdventureWorksSqliteFixture.CreateContext(); + protected override ConventionSet CreateConventionSet() => SqliteConventionSetBuilder.Build(); } }