From 8cd5a3f0e966dc5bfeed6decc2239bc97db81f77 Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Tue, 22 Dec 2020 11:29:14 -0800 Subject: [PATCH 01/14] Scaffolding --- Adapters/V4/Unity.v4.csproj | 14 --- Adapters/V4/UnityAdapterV4.cs | 12 -- Adapters/V4/UnityContainerAPI.cs | 11 -- Adapters/V4/UnityRegisterAPI.cs | 11 -- Adapters/V4/UnityResolution.cs | 11 -- Adapters/V5/Unity.v5.csproj | 14 --- Adapters/V5/UnityContainerAPI.cs | 11 -- Adapters/V5/UnityRegisterAPI.cs | 11 -- Adapters/V5/UnityResolution.cs | 11 -- Adapters/V6/Unity.v6.csproj | 14 --- Adapters/V6/UnityAdapterV6.cs | 12 -- Adapters/V6/UnityContainerAPI.cs | 12 -- Adapters/V6/UnityRegisterAPI.cs | 32 ----- Adapters/V6/UnityResolution.cs | 12 -- Benchmarks Tests.sln | 56 --------- Benchmarks/Benchmarks.csproj | 36 +++--- .../BenchmarksBase.cs | 8 +- Benchmarks/Container/ContainerAPI.cs | 90 -------------- Benchmarks/Container/Create.cs | 30 +++++ Benchmarks/Container/RegisterAPI.cs | 90 -------------- .../Pipeline/Pipeline.FromRegistered.cs | 27 ----- Benchmarks/Pipeline/Pipeline.Setup.cs | 114 ------------------ Benchmarks/Resolution/Resolve.Setup.cs | 5 + Container Benchmarks.sln | 36 ++++++ NuGet.Config | 6 + Runner/Program.cs | 18 +-- Runner/Runner.csproj | 12 +- Tests/Tests.csproj | 40 ++++++ Tests/TetsBaseline.cs | 17 +++ 29 files changed, 178 insertions(+), 595 deletions(-) delete mode 100644 Adapters/V4/Unity.v4.csproj delete mode 100644 Adapters/V4/UnityAdapterV4.cs delete mode 100644 Adapters/V4/UnityContainerAPI.cs delete mode 100644 Adapters/V4/UnityRegisterAPI.cs delete mode 100644 Adapters/V4/UnityResolution.cs delete mode 100644 Adapters/V5/Unity.v5.csproj delete mode 100644 Adapters/V5/UnityContainerAPI.cs delete mode 100644 Adapters/V5/UnityRegisterAPI.cs delete mode 100644 Adapters/V5/UnityResolution.cs delete mode 100644 Adapters/V6/Unity.v6.csproj delete mode 100644 Adapters/V6/UnityAdapterV6.cs delete mode 100644 Adapters/V6/UnityContainerAPI.cs delete mode 100644 Adapters/V6/UnityRegisterAPI.cs delete mode 100644 Adapters/V6/UnityResolution.cs delete mode 100644 Benchmarks Tests.sln rename Adapters/V5/UnityAdapterV5.cs => Benchmarks/BenchmarksBase.cs (58%) delete mode 100644 Benchmarks/Container/ContainerAPI.cs create mode 100644 Benchmarks/Container/Create.cs delete mode 100644 Benchmarks/Container/RegisterAPI.cs delete mode 100644 Benchmarks/Pipeline/Pipeline.FromRegistered.cs delete mode 100644 Benchmarks/Pipeline/Pipeline.Setup.cs create mode 100644 Container Benchmarks.sln create mode 100644 NuGet.Config create mode 100644 Tests/Tests.csproj create mode 100644 Tests/TetsBaseline.cs diff --git a/Adapters/V4/Unity.v4.csproj b/Adapters/V4/Unity.v4.csproj deleted file mode 100644 index fe8bcb4..0000000 --- a/Adapters/V4/Unity.v4.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Unity Container Regression Tests - Copyright © .NET Foundation and Contributors. All Rights Reserved - false - net462 - - - - - - - \ No newline at end of file diff --git a/Adapters/V4/UnityAdapterV4.cs b/Adapters/V4/UnityAdapterV4.cs deleted file mode 100644 index 7525e7d..0000000 --- a/Adapters/V4/UnityAdapterV4.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Unity.v4 -{ - public class UnityAdapterV4 - { - } -} diff --git a/Adapters/V4/UnityContainerAPI.cs b/Adapters/V4/UnityContainerAPI.cs deleted file mode 100644 index 839c037..0000000 --- a/Adapters/V4/UnityContainerAPI.cs +++ /dev/null @@ -1,11 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; -using Unity.Benchmarks; - -namespace Unity.v4 -{ - [ShortRunJob(RuntimeMoniker.Net462)] - public class UnityContainerAPI : ContainerAPI - { - } -} diff --git a/Adapters/V4/UnityRegisterAPI.cs b/Adapters/V4/UnityRegisterAPI.cs deleted file mode 100644 index f58f399..0000000 --- a/Adapters/V4/UnityRegisterAPI.cs +++ /dev/null @@ -1,11 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; -using Unity.Benchmarks; - -namespace Unity.v4 -{ - [ShortRunJob(RuntimeMoniker.Net462)] - public class UnityRegister : RegisterAPI - { - } -} diff --git a/Adapters/V4/UnityResolution.cs b/Adapters/V4/UnityResolution.cs deleted file mode 100644 index f04c3a0..0000000 --- a/Adapters/V4/UnityResolution.cs +++ /dev/null @@ -1,11 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; -using Unity.Benchmarks; - -namespace Unity.v4 -{ - [SimpleJob(RuntimeMoniker.Net462)] - public class UnityResolution : ResolutionBenchmarks - { - } -} diff --git a/Adapters/V5/Unity.v5.csproj b/Adapters/V5/Unity.v5.csproj deleted file mode 100644 index 49dfce4..0000000 --- a/Adapters/V5/Unity.v5.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Unity Container Regression Tests - Copyright © .NET Foundation and Contributors. All Rights Reserved - false - net472 - - - - - - - \ No newline at end of file diff --git a/Adapters/V5/UnityContainerAPI.cs b/Adapters/V5/UnityContainerAPI.cs deleted file mode 100644 index 92a6b94..0000000 --- a/Adapters/V5/UnityContainerAPI.cs +++ /dev/null @@ -1,11 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; -using Unity.Benchmarks; - -namespace Unity.v5 -{ - [ShortRunJob(RuntimeMoniker.Net472)] - public class UnityContainerAPI : ContainerAPI - { - } -} diff --git a/Adapters/V5/UnityRegisterAPI.cs b/Adapters/V5/UnityRegisterAPI.cs deleted file mode 100644 index 9e50f30..0000000 --- a/Adapters/V5/UnityRegisterAPI.cs +++ /dev/null @@ -1,11 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; -using Unity.Benchmarks; - -namespace Unity.v5 -{ - [ShortRunJob(RuntimeMoniker.Net472)] - public class UnityRegisterAPI : RegisterAPI - { - } -} diff --git a/Adapters/V5/UnityResolution.cs b/Adapters/V5/UnityResolution.cs deleted file mode 100644 index 1caebb9..0000000 --- a/Adapters/V5/UnityResolution.cs +++ /dev/null @@ -1,11 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; -using Unity.Benchmarks; - -namespace Unity.v5 -{ - [SimpleJob(RuntimeMoniker.Net472)] - public class UnityResolution : ResolutionBenchmarks - { - } -} diff --git a/Adapters/V6/Unity.v6.csproj b/Adapters/V6/Unity.v6.csproj deleted file mode 100644 index d52e8ab..0000000 --- a/Adapters/V6/Unity.v6.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Unity Container Regression Tests - Copyright © .NET Foundation and Contributors. All Rights Reserved - false - net48;net50 - - - - - - - \ No newline at end of file diff --git a/Adapters/V6/UnityAdapterV6.cs b/Adapters/V6/UnityAdapterV6.cs deleted file mode 100644 index 501f894..0000000 --- a/Adapters/V6/UnityAdapterV6.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Unity.v6 -{ - public class UnityAdapterV6 - { - } -} diff --git a/Adapters/V6/UnityContainerAPI.cs b/Adapters/V6/UnityContainerAPI.cs deleted file mode 100644 index cd0f150..0000000 --- a/Adapters/V6/UnityContainerAPI.cs +++ /dev/null @@ -1,12 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; -using Unity.Benchmarks; - -namespace Unity.v6 -{ - [ShortRunJob(RuntimeMoniker.Net48)] - [SimpleJob(RuntimeMoniker.NetCoreApp50)] - public class UnityContainerAPI : ContainerAPI - { - } -} diff --git a/Adapters/V6/UnityRegisterAPI.cs b/Adapters/V6/UnityRegisterAPI.cs deleted file mode 100644 index f7110bd..0000000 --- a/Adapters/V6/UnityRegisterAPI.cs +++ /dev/null @@ -1,32 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; -using Unity.Benchmarks; -using Unity.Lifetime; -using Unity.Resolution; - -namespace Unity.v6 -{ - [ShortRunJob(RuntimeMoniker.Net48)] - [SimpleJob(RuntimeMoniker.NetCoreApp50)] - public class UnityRegisterAPI : RegisterAPI - { - protected static ResolveDelegate ResolveDelegate = (ref IResolveContext c) => c.Type; - protected RegistrationDescriptor[] registrations; - - public override void IterationSetup() - { - base.IterationSetup(); - registrations = new[] - { - new RegistrationDescriptor(typeof(object), null, (ITypeLifetimeManager)Manager1, typeof(object)), - new RegistrationDescriptor(new object(), Name, (IInstanceLifetimeManager)Manager2, typeof(object)), - new RegistrationDescriptor(ResolveDelegate, "string", (IFactoryLifetimeManager)Manager3, typeof(string)) - }; - } - - //[Benchmark(Description = "Register()", OperationsPerInvoke = 3)] - //[BenchmarkCategory("register", "descriptors")] - //public object Register() - // => Container.Register(registrations); - } -} diff --git a/Adapters/V6/UnityResolution.cs b/Adapters/V6/UnityResolution.cs deleted file mode 100644 index 8c6f4b2..0000000 --- a/Adapters/V6/UnityResolution.cs +++ /dev/null @@ -1,12 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; -using Unity.Benchmarks; - -namespace Unity.v6 -{ - [SimpleJob(RuntimeMoniker.Net48)] - [SimpleJob(RuntimeMoniker.NetCoreApp50)] - public class UnityResolution : ResolutionBenchmarks - { - } -} diff --git a/Benchmarks Tests.sln b/Benchmarks Tests.sln deleted file mode 100644 index b319e25..0000000 --- a/Benchmarks Tests.sln +++ /dev/null @@ -1,56 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30320.27 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Runner", "Runner\Runner.csproj", "{925F5BA8-FC9D-45BC-8013-AF95C67ED742}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "Benchmarks\Benchmarks.csproj", "{023E0805-E13F-48F6-B0AC-776E7DAC8E18}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Adapters", "Adapters", "{5B7A2174-A6E6-4B28-9C42-569275D7B3DF}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Unity.v4", "Adapters\V4\Unity.v4.csproj", "{52CA989F-F741-4E77-A82F-9930C97B7161}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Unity.v5", "Adapters\V5\Unity.v5.csproj", "{3E921D4E-E8EE-4AB1-B2E9-03D36E4FCFFB}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Unity.v6", "Adapters\V6\Unity.v6.csproj", "{9D376979-A9B6-497E-965C-397E59442A12}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {925F5BA8-FC9D-45BC-8013-AF95C67ED742}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {925F5BA8-FC9D-45BC-8013-AF95C67ED742}.Debug|Any CPU.Build.0 = Debug|Any CPU - {925F5BA8-FC9D-45BC-8013-AF95C67ED742}.Release|Any CPU.ActiveCfg = Release|Any CPU - {925F5BA8-FC9D-45BC-8013-AF95C67ED742}.Release|Any CPU.Build.0 = Release|Any CPU - {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Debug|Any CPU.Build.0 = Debug|Any CPU - {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Release|Any CPU.ActiveCfg = Release|Any CPU - {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Release|Any CPU.Build.0 = Release|Any CPU - {52CA989F-F741-4E77-A82F-9930C97B7161}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {52CA989F-F741-4E77-A82F-9930C97B7161}.Debug|Any CPU.Build.0 = Debug|Any CPU - {52CA989F-F741-4E77-A82F-9930C97B7161}.Release|Any CPU.ActiveCfg = Release|Any CPU - {52CA989F-F741-4E77-A82F-9930C97B7161}.Release|Any CPU.Build.0 = Release|Any CPU - {3E921D4E-E8EE-4AB1-B2E9-03D36E4FCFFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3E921D4E-E8EE-4AB1-B2E9-03D36E4FCFFB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3E921D4E-E8EE-4AB1-B2E9-03D36E4FCFFB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3E921D4E-E8EE-4AB1-B2E9-03D36E4FCFFB}.Release|Any CPU.Build.0 = Release|Any CPU - {9D376979-A9B6-497E-965C-397E59442A12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9D376979-A9B6-497E-965C-397E59442A12}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9D376979-A9B6-497E-965C-397E59442A12}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9D376979-A9B6-497E-965C-397E59442A12}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {52CA989F-F741-4E77-A82F-9930C97B7161} = {5B7A2174-A6E6-4B28-9C42-569275D7B3DF} - {3E921D4E-E8EE-4AB1-B2E9-03D36E4FCFFB} = {5B7A2174-A6E6-4B28-9C42-569275D7B3DF} - {9D376979-A9B6-497E-965C-397E59442A12} = {5B7A2174-A6E6-4B28-9C42-569275D7B3DF} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {032A4232-BBBB-431E-A478-D3EAA6CA330C} - EndGlobalSection -EndGlobal diff --git a/Benchmarks/Benchmarks.csproj b/Benchmarks/Benchmarks.csproj index 60b5a63..c314e48 100644 --- a/Benchmarks/Benchmarks.csproj +++ b/Benchmarks/Benchmarks.csproj @@ -1,24 +1,11 @@  - Unity Container Regression Tests - Copyright © .NET Foundation and Contributors. All Rights Reserved - true - package.snk - false ..\..\Container\src\Unity.Container.csproj - - - net462;net472;net48;net50 net50 - - - - - - + @@ -30,4 +17,25 @@ + + + + UNITY_V6;$(DefineConstants) + UNITY_V6;$(DefineConstants) + UNITY_V5;$(DefineConstants) + UNITY_V4;$(DefineConstants) + UNITY_V4;$(DefineConstants) + + + + + + + + + Unity Container Regression Tests + Copyright © .NET Foundation and Contributors. All Rights Reserved + + + \ No newline at end of file diff --git a/Adapters/V5/UnityAdapterV5.cs b/Benchmarks/BenchmarksBase.cs similarity index 58% rename from Adapters/V5/UnityAdapterV5.cs rename to Benchmarks/BenchmarksBase.cs index 060c8ec..8416cc5 100644 --- a/Adapters/V5/UnityAdapterV5.cs +++ b/Benchmarks/BenchmarksBase.cs @@ -4,9 +4,15 @@ using System.Text; using System.Threading.Tasks; +#if UNITY_V4 +namespace Unity.v4 +#elif UNITY_V5 namespace Unity.v5 +#else +namespace Unity.v6 +#endif { - public class UnityAdapterV5 + public class BenchmarksBase { } } diff --git a/Benchmarks/Container/ContainerAPI.cs b/Benchmarks/Container/ContainerAPI.cs deleted file mode 100644 index ddb6b0e..0000000 --- a/Benchmarks/Container/ContainerAPI.cs +++ /dev/null @@ -1,90 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Engines; -using System.Collections.Generic; -using System.Reflection; -using System.Linq; -using System; -#if NET462 -using Microsoft.Practices.Unity; -#else -using Unity.Injection; -using Unity.Lifetime; -using Unity; -#endif - -namespace Unity.Benchmarks -{ - public class ContainerAPI - { - protected IUnityContainer Container; - protected Consumer Consumer = new Consumer(); - protected static string Name = "name"; - - protected static IInstanceLifetimeManager Manager = new ContainerControlledLifetimeManager(); - private static IEnumerable DefinedTypes = Assembly.GetAssembly(typeof(int)).DefinedTypes.Take(1000); - protected static string[] TestNames = Enumerable.Repeat(null, 4) - .Concat(DefinedTypes.Take(5).Select(t => t.Name)) - .Concat(DefinedTypes.Select(t => t.Name).Distinct().Take(100)) - .ToArray(); - protected static Type[] TestTypes = DefinedTypes.Where(t => t != typeof(IServiceProvider)) - .ToArray(); - static int size = 0; - static int position = 0; - protected static object Instance = new object(); - protected static RegistrationDescriptor[] RegistrationsData = TestNames.Select(name => - { - var types = new Type[(++size & 0x7F)]; - - Array.Copy(TestTypes, position, types, 0, types.Length); - position = (position + types.Length) & 0x4FF; - - return new RegistrationDescriptor(Instance, name, Manager, types); - }).ToArray(); - - - [GlobalSetup] - public virtual void GlobalSetup() - => Container = new UnityContainer().Register(RegistrationsData); - - - [Benchmark(Description = "new UnityContainer()")] - [BenchmarkCategory("new")] - public object NewUnityContainer() - => new UnityContainer(); - - - [Benchmark(Description = "CreateChildContainer()")] - [BenchmarkCategory("new", "child")] - public object NewChildContainer() - => Container.CreateChildContainer(); - - - [Benchmark(Description = "Container.Registrations")] - [BenchmarkCategory("registrations")] - public object Registrations() - => Container.Registrations; - - - [Benchmark(Description = "Registrations.ToArray(6351)")] - [BenchmarkCategory("registrations", "ToArray")] - public void RegistrationsToArray() - => Container.Registrations.Consume(Consumer); - - [Benchmark(Description = "Registrations.PerRegistration", OperationsPerInvoke = 6351)] - [BenchmarkCategory("registrations", "ToArray")] - public void RegistrationsPerRegistration() - => Container.Registrations.Consume(Consumer); - - - [Benchmark(Description = "Container.IsRegistered(true)")] - [BenchmarkCategory("check", "true")] - public virtual bool IsRegistered() - => Container.IsRegistered(typeof(IUnityContainer), null); - - - [Benchmark(Description = "Container.IsRegistered(false)")] - [BenchmarkCategory("check", "false")] - public virtual bool IsNotRegistered() - => Container.IsRegistered(typeof(object), null); - } -} diff --git a/Benchmarks/Container/Create.cs b/Benchmarks/Container/Create.cs new file mode 100644 index 0000000..ddd0d84 --- /dev/null +++ b/Benchmarks/Container/Create.cs @@ -0,0 +1,30 @@ +using BenchmarkDotNet.Attributes; +using System; +using BenchmarkDotNet.Jobs; +#if UNITY_V4 +using Microsoft.Practices.Unity; +#else +using Unity.Injection; +using Unity.Lifetime; +using Unity; +#endif + +namespace Unity.Benchmarks +{ + [SimpleJob(RuntimeMoniker.NetCoreApp50)] + [SimpleJob(RuntimeMoniker.Net48)] + [SimpleJob(RuntimeMoniker.Net472)] + [SimpleJob(RuntimeMoniker.Net462)] + public partial class Create + { +#if UNITY_V4 + [Benchmark(Description = "new UnityContainer(4)"), BenchmarkCategory("new", "UnityContainer")] +#elif UNITY_V5 + [Benchmark(Description = "new UnityContainer(5)"), BenchmarkCategory("new", "UnityContainer")] +#else + [Benchmark(Description = "new UnityContainer(6)"), BenchmarkCategory("new", "UnityContainer")] +#endif + + public object New_UnityContainer() => new UnityContainer(); + } +} diff --git a/Benchmarks/Container/RegisterAPI.cs b/Benchmarks/Container/RegisterAPI.cs deleted file mode 100644 index d1caf85..0000000 --- a/Benchmarks/Container/RegisterAPI.cs +++ /dev/null @@ -1,90 +0,0 @@ -using BenchmarkDotNet.Attributes; -using System; -using Unity.Resolution; -#if NET462 -using Microsoft.Practices.Unity; -#else -using Unity.Injection; -using Unity.Lifetime; -using Unity; -#endif - -namespace Unity.Benchmarks -{ - public class RegisterAPI - { - protected static LifetimeManager Manager1; - protected static LifetimeManager Manager2; - protected static LifetimeManager Manager3; - protected static IUnityContainer Container; - protected static Func Factory = (c, t, n) => c; - protected const string Name = "name"; - protected object Instance1 = new object(); - protected object Instance2 = new object(); - protected object Instance3 = "object"; -#if NET462 - protected InjectionFactory InjectionFactory = new InjectionFactory(Factory); -#endif - - - //[IterationSetup] - public virtual void IterationSetup() - { - Container = new UnityContainer(); - Manager1 = new ContainerControlledLifetimeManager(); - Manager2 = new ContainerControlledLifetimeManager(); - Manager3 = new ContainerControlledLifetimeManager(); - } - - [Benchmark(Description = "RegisterType()", OperationsPerInvoke = 3)] - [BenchmarkCategory("register", "type")] - public virtual object RegisterType() - { -#if NET462 - Container.RegisterType(typeof(object), Manager1); - Container.RegisterType(typeof(object), Name, Manager2); - Container.RegisterType(typeof(string), "string", Manager3); -#else - Container.RegisterType(typeof(object), (ITypeLifetimeManager)Manager1); - Container.RegisterType(typeof(object), Name, (ITypeLifetimeManager)Manager2); - Container.RegisterType(typeof(string), "string", (ITypeLifetimeManager)Manager3); -#endif - - return Container; - } - - [Benchmark(Description = "RegisterInstance()", OperationsPerInvoke = 3)] - [BenchmarkCategory("register", "instance")] - public virtual object RegisterInstance() - { -#if NET462 - Container.RegisterInstance(typeof(object), Instance1, Manager1); - Container.RegisterInstance(typeof(object), Name, Instance2, Manager2); - Container.RegisterInstance(typeof(string), "string", Instance3, Manager3); -#else - Container.RegisterInstance(typeof(object), Instance1, (IInstanceLifetimeManager)Manager1); - Container.RegisterInstance(typeof(object), Name, Instance2, (IInstanceLifetimeManager)Manager2); - Container.RegisterInstance(typeof(string), "string", Instance3, (IInstanceLifetimeManager)Manager3); -#endif - - return Container; - } - - [Benchmark(Description = "RegisterFactory()", OperationsPerInvoke = 3)] - [BenchmarkCategory("register", "factory")] - public virtual object RegisterFactory() - { -#if NET462 - Container.RegisterType(typeof(object), Manager1, InjectionFactory); - Container.RegisterType(typeof(object), Name, Manager2, InjectionFactory); - Container.RegisterType(typeof(string), "string", Manager3, InjectionFactory); -#else - Container.RegisterFactory(typeof(object), Factory, (IFactoryLifetimeManager)Manager1); - Container.RegisterFactory(typeof(object), Name, Factory, (IFactoryLifetimeManager)Manager2); - Container.RegisterFactory(typeof(string), "string", Factory, (IFactoryLifetimeManager)Manager3); - -#endif - return Container; - } - } -} diff --git a/Benchmarks/Pipeline/Pipeline.FromRegistered.cs b/Benchmarks/Pipeline/Pipeline.FromRegistered.cs deleted file mode 100644 index 3570363..0000000 --- a/Benchmarks/Pipeline/Pipeline.FromRegistered.cs +++ /dev/null @@ -1,27 +0,0 @@ -using BenchmarkDotNet.Attributes; -using System; -#if NET462 -using Microsoft.Practices.Unity; -#else -using Unity.Injection; -using Unity.Lifetime; -using Unity; -#endif - -namespace Unity.Benchmarks -{ - public partial class PipelineBenchmarks - { - [Benchmark] - public object FromRegistered_Complete_Transient() - => Container.Resolve(typeof(Service), EveryTime); - - [Benchmark] - public object FromRegistered_Complete_Balanced_() - => Container.Resolve(typeof(Service), OnceInAWhile); - - [Benchmark] - public object FromRegistered_Complete_Singleton() - => Container.Resolve(typeof(Service), OnceInLifetime); - } -} diff --git a/Benchmarks/Pipeline/Pipeline.Setup.cs b/Benchmarks/Pipeline/Pipeline.Setup.cs deleted file mode 100644 index 76f7296..0000000 --- a/Benchmarks/Pipeline/Pipeline.Setup.cs +++ /dev/null @@ -1,114 +0,0 @@ -using BenchmarkDotNet.Attributes; -using System; -using System.Collections.Generic; -using Unity.Resolution; -using Unity.Container; -using System.Reflection; -#if NET462 -using Microsoft.Practices.Unity; -#else -using Unity.Injection; -using Unity.Lifetime; -using Unity; -#endif - -namespace Unity.Benchmarks -{ - public partial class PipelineBenchmarks - { - const string EveryTime = "EveryTime"; - const string OnceInLifetime = "OnceInLifetime"; - const string OnceInAWhile = "OnceInAWhile"; - -#if NET462 || NET472 - protected IUnityContainer Container; -#else - protected IUnityContainer Container; - protected IUnityContainerAsync ContainerAsync; - protected IServiceProvider ServiceProvider; -#endif - - [GlobalSetup] - public virtual void GlobalSetup() - { - Container = new UnityContainer() - .RegisterType(typeof(Service), EveryTime, new EveryTimeManager()) - .RegisterType(typeof(Service), OnceInLifetime, new OnceInLifetimeManager()) - .RegisterType(typeof(Service), OnceInAWhile, new OnceInAWhileManager()); -#if !NET462 && !NET472 - ContainerAsync = (IUnityContainerAsync)Container; - ServiceProvider = (IServiceProvider)Container; -#endif - } - - - public interface IService { } - - public class Service : IService { } - - public class OtherService : IService { } - - public class CompleteService : IService { } - - - public class EveryTimeManager : LifetimeManager, ITypeLifetimeManager - { - public override ResolutionStyle Style => ResolutionStyle.EveryTime; - - protected override LifetimeManager OnCreateLifetimeManager() => throw new NotSupportedException(); - - public override void SetValue(object newValue, ICollection scope) { } - - public override object TryGetValue(ICollection scope) - { - Pipeline = null; - return UnityContainer.NoValue; - } - public override object GetValue(ICollection scope) - { - Pipeline = null; - return UnityContainer.NoValue; - } - } - - public class OnceInLifetimeManager : LifetimeManager, ITypeLifetimeManager - { - public override ResolutionStyle Style => ResolutionStyle.OnceInLifetime; - - protected override LifetimeManager OnCreateLifetimeManager() => throw new NotSupportedException(); - - public override void SetValue(object newValue, ICollection lifetime) - { } - public override object TryGetValue(ICollection lifetime) - { - Pipeline = null; - return UnityContainer.NoValue; - } - public override object GetValue(ICollection lifetime) - { - Pipeline = null; - return UnityContainer.NoValue; - } - } - - public class OnceInAWhileManager : LifetimeManager, ITypeLifetimeManager - { - public override ResolutionStyle Style => ResolutionStyle.OnceInWhile; - - protected override LifetimeManager OnCreateLifetimeManager() => throw new NotSupportedException(); - - public override void SetValue(object newValue, ICollection lifetime) - { } - public override object TryGetValue(ICollection lifetime) - { - Pipeline = null; - return UnityContainer.NoValue; - } - public override object GetValue(ICollection lifetime) - { - Pipeline = null; - return UnityContainer.NoValue; - } - } - } -} diff --git a/Benchmarks/Resolution/Resolve.Setup.cs b/Benchmarks/Resolution/Resolve.Setup.cs index 9489f6e..646e6aa 100644 --- a/Benchmarks/Resolution/Resolve.Setup.cs +++ b/Benchmarks/Resolution/Resolve.Setup.cs @@ -1,5 +1,6 @@ using BenchmarkDotNet.Attributes; using System; +using BenchmarkDotNet.Jobs; #if NET462 using Microsoft.Practices.Unity; #else @@ -10,6 +11,10 @@ namespace Unity.Benchmarks { + [ShortRunJob(RuntimeMoniker.Net462)] + [SimpleJob(RuntimeMoniker.Net472)] + [ShortRunJob(RuntimeMoniker.Net48)] + [SimpleJob(RuntimeMoniker.NetCoreApp50)] public partial class ResolutionBenchmarks { #if NET462 || NET472 diff --git a/Container Benchmarks.sln b/Container Benchmarks.sln new file mode 100644 index 0000000..4f74fcc --- /dev/null +++ b/Container Benchmarks.sln @@ -0,0 +1,36 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30320.27 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Runner", "Runner\Runner.csproj", "{925F5BA8-FC9D-45BC-8013-AF95C67ED742}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "Benchmarks\Benchmarks.csproj", "{023E0805-E13F-48F6-B0AC-776E7DAC8E18}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{0F256661-A8DC-49FA-AC8F-512243486A08}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {925F5BA8-FC9D-45BC-8013-AF95C67ED742}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {925F5BA8-FC9D-45BC-8013-AF95C67ED742}.Debug|Any CPU.Build.0 = Debug|Any CPU + {925F5BA8-FC9D-45BC-8013-AF95C67ED742}.Release|Any CPU.ActiveCfg = Release|Any CPU + {925F5BA8-FC9D-45BC-8013-AF95C67ED742}.Release|Any CPU.Build.0 = Release|Any CPU + {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Debug|Any CPU.Build.0 = Debug|Any CPU + {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Release|Any CPU.ActiveCfg = Release|Any CPU + {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Release|Any CPU.Build.0 = Release|Any CPU + {0F256661-A8DC-49FA-AC8F-512243486A08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0F256661-A8DC-49FA-AC8F-512243486A08}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F256661-A8DC-49FA-AC8F-512243486A08}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {032A4232-BBBB-431E-A478-D3EAA6CA330C} + EndGlobalSection +EndGlobal diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..dadc1a2 --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Runner/Program.cs b/Runner/Program.cs index 47cf60d..dd06e1e 100644 --- a/Runner/Program.cs +++ b/Runner/Program.cs @@ -1,7 +1,7 @@ using BenchmarkDotNet.Running; -using Unity.v4; -using Unity.v5; -using Unity.v6; +using System.IO; +using System.Linq; +using System.Reflection; namespace Unity.Benchmark { @@ -9,12 +9,12 @@ class Program { static void Main(string[] args) { - BenchmarkSwitcher.FromAssemblies(new[] - { - typeof(UnityAdapterV4).Assembly, - typeof(UnityAdapterV5).Assembly, - typeof(UnityAdapterV6).Assembly, - }).Run(args); + //BenchmarkSwitcher.FromAssemblies(new[] + //{ + // typeof(Unity.v4.BenchmarksBase).Assembly, + // typeof(Unity.v5.BenchmarksBase).Assembly, + // typeof(Unity.v6.BenchmarksBase).Assembly, + //}).Run(args); } } } diff --git a/Runner/Runner.csproj b/Runner/Runner.csproj index 0c866da..cb77001 100644 --- a/Runner/Runner.csproj +++ b/Runner/Runner.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net50 NU1702 @@ -17,10 +17,10 @@ - - - - - + + + + + diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj new file mode 100644 index 0000000..58156a5 --- /dev/null +++ b/Tests/Tests.csproj @@ -0,0 +1,40 @@ + + + + ..\..\Container\src\Unity.Container.csproj + net462;net472;net48;net50 + net50 + + + + + + UNITY_V6;$(DefineConstants) + UNITY_V6;$(DefineConstants) + UNITY_V5;$(DefineConstants) + UNITY_V4;$(DefineConstants) + UNITY_V4;$(DefineConstants) + + + + + + + + + + Unity Container Regression Tests + Copyright © .NET Foundation and Contributors. All Rights Reserved + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/TetsBaseline.cs b/Tests/TetsBaseline.cs new file mode 100644 index 0000000..b062bcd --- /dev/null +++ b/Tests/TetsBaseline.cs @@ -0,0 +1,17 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tests +{ + [TestClass] + public class TetsBaseline + { + [TestMethod] + public void Baseline() + { } + } +} From 3fd52a39d194337d6471643b4b347ee74b10200f Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Tue, 22 Dec 2020 12:32:55 -0800 Subject: [PATCH 02/14] Adding scaffolding --- Benchmarks/Container/Create.cs | 48 ++++++++++++++++++++++++------- Tests/BenchmarkTestBase.cs | 52 ++++++++++++++++++++++++++++++++++ Tests/Container/TestCreate.cs | 25 ++++++++++++++++ Tests/Tests.csproj | 1 + Tests/TetsBaseline.cs | 17 ----------- 5 files changed, 115 insertions(+), 28 deletions(-) create mode 100644 Tests/BenchmarkTestBase.cs create mode 100644 Tests/Container/TestCreate.cs delete mode 100644 Tests/TetsBaseline.cs diff --git a/Benchmarks/Container/Create.cs b/Benchmarks/Container/Create.cs index ddd0d84..fd0335a 100644 --- a/Benchmarks/Container/Create.cs +++ b/Benchmarks/Container/Create.cs @@ -3,28 +3,54 @@ using BenchmarkDotNet.Jobs; #if UNITY_V4 using Microsoft.Practices.Unity; + +namespace Unity.v4 +{ + [SimpleJob(RuntimeMoniker.Net462)] + +#elif UNITY_V5 + +namespace Unity.v5 +{ + [SimpleJob(RuntimeMoniker.Net472)] + #else using Unity.Injection; using Unity.Lifetime; using Unity; -#endif -namespace Unity.Benchmarks +namespace Unity.v6 { [SimpleJob(RuntimeMoniker.NetCoreApp50)] [SimpleJob(RuntimeMoniker.Net48)] - [SimpleJob(RuntimeMoniker.Net472)] - [SimpleJob(RuntimeMoniker.Net462)] +#endif public partial class Create { -#if UNITY_V4 - [Benchmark(Description = "new UnityContainer(4)"), BenchmarkCategory("new", "UnityContainer")] -#elif UNITY_V5 - [Benchmark(Description = "new UnityContainer(5)"), BenchmarkCategory("new", "UnityContainer")] -#else - [Benchmark(Description = "new UnityContainer(6)"), BenchmarkCategory("new", "UnityContainer")] -#endif + private static IUnityContainer Container; + + [GlobalSetup] + public static void InitializeClass() + { + Container = new UnityContainer(); + } + + //[IterationSetup] + //public void IterationSetup() + //{ + //} + //[IterationCleanup] + //public void IterationCleanup() + //{ + //} + + + [Benchmark(Description = "new UnityContainer()"), BenchmarkCategory("new", "UnityContainer")] public object New_UnityContainer() => new UnityContainer(); + + + + [Benchmark(Description = "CreateChildContainer()"), BenchmarkCategory("new", "ChildContainer")] + public object CreateChildContainer() => Container.CreateChildContainer(); } } diff --git a/Tests/BenchmarkTestBase.cs b/Tests/BenchmarkTestBase.cs new file mode 100644 index 0000000..fd5d700 --- /dev/null +++ b/Tests/BenchmarkTestBase.cs @@ -0,0 +1,52 @@ +using BenchmarkDotNet.Attributes; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Linq; +using System.Reflection; + +namespace Benchmark.Tests +{ + [TestClass] + public class BenchmarkTestBase + where TBenchmark : class, new() + { + protected static TBenchmark Benchmark = new TBenchmark(); + private static Action IterationSetupAction; + private static Action IterationCleanupAction; + + #region Constructors + + static BenchmarkTestBase() + { + var methods = typeof(TBenchmark).GetMethods(); + var globalSetup = methods.Where(info => info.IsDefined(typeof(GlobalSetupAttribute), true)) + .FirstOrDefault(); + globalSetup?.Invoke(null, Array.Empty()); + + var method = methods.Where(info => info.IsDefined(typeof(IterationSetupAttribute), true)) + .FirstOrDefault(); + + if (method is not null) + IterationSetupAction = (Action)method.CreateDelegate(typeof(Action), Benchmark); + + method = methods.Where(info => info.IsDefined(typeof(IterationCleanupAttribute), true)) + .FirstOrDefault(); + + if (method is not null) + IterationCleanupAction = (Action)method.CreateDelegate(typeof(Action), Benchmark); + } + + #endregion + + + #region Scaffolding + + [TestInitialize] + public virtual void IterationSetup() => IterationSetupAction?.Invoke(); + + [TestCleanup] + public virtual void IterationCleanup() => IterationCleanupAction?.Invoke(); + + #endregion + } +} diff --git a/Tests/Container/TestCreate.cs b/Tests/Container/TestCreate.cs new file mode 100644 index 0000000..09ec5d6 --- /dev/null +++ b/Tests/Container/TestCreate.cs @@ -0,0 +1,25 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Benchmark.Tests; +#if UNITY_V4 +using Unity.v4; +#elif UNITY_V5 +using Unity.v5; +#else +using Unity.v6; +#endif + + +namespace Continer +{ + [TestClass] + public partial class TestCreate : BenchmarkTestBase + { + [TestMethod] + public void New_UnityContainer() + => Assert.IsNotNull(Benchmark.New_UnityContainer()); + + [TestMethod] + public void CreateChildContainer() + => Assert.IsNotNull(Benchmark.CreateChildContainer()); + } +} diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 58156a5..d37ce42 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -4,6 +4,7 @@ ..\..\Container\src\Unity.Container.csproj net462;net472;net48;net50 net50 + latest diff --git a/Tests/TetsBaseline.cs b/Tests/TetsBaseline.cs deleted file mode 100644 index b062bcd..0000000 --- a/Tests/TetsBaseline.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tests -{ - [TestClass] - public class TetsBaseline - { - [TestMethod] - public void Baseline() - { } - } -} From d6a8102d4e3b21bd8500efdea7b149187082cd00 Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Tue, 22 Dec 2020 13:55:56 -0800 Subject: [PATCH 03/14] Refactoring --- Benchmarks/Benchmarks.csproj | 2 +- Benchmarks/BenchmarksBase.cs | 8 +------- Benchmarks/Container/Create.cs | 4 ++-- Benchmarks/package.snk | Bin 596 -> 0 bytes Tests/{Tests.csproj => Benchmarks.Tests.csproj} | 0 5 files changed, 4 insertions(+), 10 deletions(-) delete mode 100644 Benchmarks/package.snk rename Tests/{Tests.csproj => Benchmarks.Tests.csproj} (100%) diff --git a/Benchmarks/Benchmarks.csproj b/Benchmarks/Benchmarks.csproj index c314e48..88e56a7 100644 --- a/Benchmarks/Benchmarks.csproj +++ b/Benchmarks/Benchmarks.csproj @@ -3,7 +3,7 @@ ..\..\Container\src\Unity.Container.csproj net462;net472;net48;net50 - net50 + net48;net50 diff --git a/Benchmarks/BenchmarksBase.cs b/Benchmarks/BenchmarksBase.cs index 8416cc5..8f352da 100644 --- a/Benchmarks/BenchmarksBase.cs +++ b/Benchmarks/BenchmarksBase.cs @@ -4,13 +4,7 @@ using System.Text; using System.Threading.Tasks; -#if UNITY_V4 -namespace Unity.v4 -#elif UNITY_V5 -namespace Unity.v5 -#else -namespace Unity.v6 -#endif +namespace Benchmarks { public class BenchmarksBase { diff --git a/Benchmarks/Container/Create.cs b/Benchmarks/Container/Create.cs index fd0335a..b42be11 100644 --- a/Benchmarks/Container/Create.cs +++ b/Benchmarks/Container/Create.cs @@ -21,8 +21,8 @@ namespace Unity.v5 namespace Unity.v6 { - [SimpleJob(RuntimeMoniker.NetCoreApp50)] - [SimpleJob(RuntimeMoniker.Net48)] + [ShortRunJob(RuntimeMoniker.NetCoreApp50)] + [ShortRunJob(RuntimeMoniker.Net48)] #endif public partial class Create { diff --git a/Benchmarks/package.snk b/Benchmarks/package.snk deleted file mode 100644 index 986f91ecb97a15bd5fe7a90808e2c43a5f895584..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50096uv0xR5T6)9AKRgh!Idbd`{cW~G>hDGB zBA31W#XA{A0e{DD&^X*~d-)jvB-KM-q?R!K{S-biNuf|{iC?_V0e$h*@ao3!Uu`9O z6<&qAH57)kK%D!0f3YbY zUw`@92PfR%y%)-dH@*jZtvtJ#iMJ6!_E*mc8d-usBYHF0f*ZkegQXrgAi`sEfbtH! zr&YDh6$1YRo0Y4&cHJ>DnO0rFhAA% zsROpNG_2GCm39ACojQNZ5`;h7HoIq!PR?m~iGi( Date: Tue, 22 Dec 2020 19:09:33 -0800 Subject: [PATCH 04/14] Restore point --- Adapters/V4/Create.cs | 10 ++++++ Adapters/V4/Unity.v4.csproj | 15 ++++++++ Adapters/V4/UnityAdapterV4.cs | 7 ++++ Adapters/V4/UnityResolution.cs | 11 ++++++ Adapters/V5/Create.cs | 10 ++++++ Adapters/V5/Unity.v5.csproj | 14 ++++++++ Adapters/V5/UnityAdapterV5.cs | 7 ++++ Adapters/V5/UnityResolution.cs | 11 ++++++ Adapters/V6/Create.cs | 11 ++++++ Adapters/V6/Unity.v6.csproj | 15 ++++++++ Adapters/V6/UnityAdapterV6.cs | 7 ++++ Adapters/V6/UnityResolution.cs | 12 +++++++ Benchmarks/BenchmarkBase.cs | 21 +++++++++++ Benchmarks/Benchmarks.csproj | 66 +++++++++++++++++++++++----------- Benchmarks/BenchmarksBase.cs | 12 ------- Benchmarks/Container/Create.cs | 35 ++++-------------- Container Benchmarks.sln | 38 ++++++++++++++++---- Runner/Program.cs | 18 +++++----- Runner/Runner.csproj | 14 +++++--- Tests/Benchmarks.Tests.csproj | 2 +- Tests/Container/TestCreate.cs | 9 +---- 21 files changed, 254 insertions(+), 91 deletions(-) create mode 100644 Adapters/V4/Create.cs create mode 100644 Adapters/V4/Unity.v4.csproj create mode 100644 Adapters/V4/UnityAdapterV4.cs create mode 100644 Adapters/V4/UnityResolution.cs create mode 100644 Adapters/V5/Create.cs create mode 100644 Adapters/V5/Unity.v5.csproj create mode 100644 Adapters/V5/UnityAdapterV5.cs create mode 100644 Adapters/V5/UnityResolution.cs create mode 100644 Adapters/V6/Create.cs create mode 100644 Adapters/V6/Unity.v6.csproj create mode 100644 Adapters/V6/UnityAdapterV6.cs create mode 100644 Adapters/V6/UnityResolution.cs create mode 100644 Benchmarks/BenchmarkBase.cs delete mode 100644 Benchmarks/BenchmarksBase.cs diff --git a/Adapters/V4/Create.cs b/Adapters/V4/Create.cs new file mode 100644 index 0000000..8ea60fa --- /dev/null +++ b/Adapters/V4/Create.cs @@ -0,0 +1,10 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Jobs; + +namespace Unity.v4 +{ + [SimpleJob(RuntimeMoniker.Net462)] + public class Create : Benchmarks.Create + { + } +} diff --git a/Adapters/V4/Unity.v4.csproj b/Adapters/V4/Unity.v4.csproj new file mode 100644 index 0000000..407245b --- /dev/null +++ b/Adapters/V4/Unity.v4.csproj @@ -0,0 +1,15 @@ + + + + Unity Container Regression Tests + Copyright © .NET Foundation and Contributors. All Rights Reserved + false + net462 + + + + + + + + \ No newline at end of file diff --git a/Adapters/V4/UnityAdapterV4.cs b/Adapters/V4/UnityAdapterV4.cs new file mode 100644 index 0000000..a58d142 --- /dev/null +++ b/Adapters/V4/UnityAdapterV4.cs @@ -0,0 +1,7 @@ +namespace Unity.v4 +{ + // Marker type for Unity Adapter v4 + public sealed class UnityAdapterV4 + { + } +} diff --git a/Adapters/V4/UnityResolution.cs b/Adapters/V4/UnityResolution.cs new file mode 100644 index 0000000..06c138d --- /dev/null +++ b/Adapters/V4/UnityResolution.cs @@ -0,0 +1,11 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Jobs; +using Unity.Benchmarks; + +namespace Unity.v4 +{ + [SimpleJob(RuntimeMoniker.Net462)] + public class UnityResolution_v4 : ResolutionBenchmarks + { + } +} diff --git a/Adapters/V5/Create.cs b/Adapters/V5/Create.cs new file mode 100644 index 0000000..24d4ad9 --- /dev/null +++ b/Adapters/V5/Create.cs @@ -0,0 +1,10 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Jobs; + +namespace Unity.v5 +{ + [SimpleJob(RuntimeMoniker.Net472)] + public class Create : Benchmarks.Create + { + } +} diff --git a/Adapters/V5/Unity.v5.csproj b/Adapters/V5/Unity.v5.csproj new file mode 100644 index 0000000..49dfce4 --- /dev/null +++ b/Adapters/V5/Unity.v5.csproj @@ -0,0 +1,14 @@ + + + + Unity Container Regression Tests + Copyright © .NET Foundation and Contributors. All Rights Reserved + false + net472 + + + + + + + \ No newline at end of file diff --git a/Adapters/V5/UnityAdapterV5.cs b/Adapters/V5/UnityAdapterV5.cs new file mode 100644 index 0000000..745b07b --- /dev/null +++ b/Adapters/V5/UnityAdapterV5.cs @@ -0,0 +1,7 @@ +namespace Unity.v5 +{ + // Marker type for Unity Adapter v5 + public sealed class UnityAdapterV5 + { + } +} diff --git a/Adapters/V5/UnityResolution.cs b/Adapters/V5/UnityResolution.cs new file mode 100644 index 0000000..f3e4bf8 --- /dev/null +++ b/Adapters/V5/UnityResolution.cs @@ -0,0 +1,11 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Jobs; +using Unity.Benchmarks; + +namespace Unity.v5 +{ + [SimpleJob(RuntimeMoniker.Net472)] + public class UnityResolution_v5 : ResolutionBenchmarks + { + } +} diff --git a/Adapters/V6/Create.cs b/Adapters/V6/Create.cs new file mode 100644 index 0000000..363e16b --- /dev/null +++ b/Adapters/V6/Create.cs @@ -0,0 +1,11 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Jobs; + + +namespace Unity.V6 +{ + [SimpleJob(RuntimeMoniker.NetCoreApp50)] + public class Create : Benchmarks.Create + { + } +} diff --git a/Adapters/V6/Unity.v6.csproj b/Adapters/V6/Unity.v6.csproj new file mode 100644 index 0000000..aa23a29 --- /dev/null +++ b/Adapters/V6/Unity.v6.csproj @@ -0,0 +1,15 @@ + + + + Unity Container Regression Tests + Copyright © .NET Foundation and Contributors. All Rights Reserved + false + net50 + + + + + + + + \ No newline at end of file diff --git a/Adapters/V6/UnityAdapterV6.cs b/Adapters/V6/UnityAdapterV6.cs new file mode 100644 index 0000000..141a1a2 --- /dev/null +++ b/Adapters/V6/UnityAdapterV6.cs @@ -0,0 +1,7 @@ +namespace Unity.v6 +{ + // Marker type for Unity Adapter v6 + public sealed class UnityAdapterV6 + { + } +} diff --git a/Adapters/V6/UnityResolution.cs b/Adapters/V6/UnityResolution.cs new file mode 100644 index 0000000..28e4250 --- /dev/null +++ b/Adapters/V6/UnityResolution.cs @@ -0,0 +1,12 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Jobs; +using Unity.Benchmarks; + +namespace Unity.v6 +{ + [SimpleJob(RuntimeMoniker.Net48)] + [SimpleJob(RuntimeMoniker.NetCoreApp50)] + public class UnityResolution_v6 : ResolutionBenchmarks + { + } +} diff --git a/Benchmarks/BenchmarkBase.cs b/Benchmarks/BenchmarkBase.cs new file mode 100644 index 0000000..177e996 --- /dev/null +++ b/Benchmarks/BenchmarkBase.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Benchmarks +{ + public class BenchmarkBase + { +#if UNITY_V4 + public const string VERSION = " v4"; +#elif UNITY_V5 + public const string VERSION = " v5"; +#elif UNITY_V6 + public const string VERSION = " v6"; +#else + public const string VERSION = ""; +#endif + } +} diff --git a/Benchmarks/Benchmarks.csproj b/Benchmarks/Benchmarks.csproj index 88e56a7..08a7245 100644 --- a/Benchmarks/Benchmarks.csproj +++ b/Benchmarks/Benchmarks.csproj @@ -2,30 +2,55 @@ ..\..\Container\src\Unity.Container.csproj - net462;net472;net48;net50 - net48;net50 + STANDALONE;$(DefineConstants) + net462;net472;net50 + net50 - - - - - - - - - - - + + + + + + + + UNITY_V4;$(DefineConstants) + $(AssemblyName).V4 + + + + + + + + UNITY_V5;$(DefineConstants) + $(AssemblyName).V5 + + + + + + + + UNITY_V6;$(DefineConstants) + $(AssemblyName).V6 + + + + + + + + + UNITY_V6;$(DefineConstants) + $(AssemblyName).Dev + + + + + - - UNITY_V6;$(DefineConstants) - UNITY_V6;$(DefineConstants) - UNITY_V5;$(DefineConstants) - UNITY_V4;$(DefineConstants) - UNITY_V4;$(DefineConstants) - @@ -37,5 +62,4 @@ Copyright © .NET Foundation and Contributors. All Rights Reserved - \ No newline at end of file diff --git a/Benchmarks/BenchmarksBase.cs b/Benchmarks/BenchmarksBase.cs deleted file mode 100644 index 8f352da..0000000 --- a/Benchmarks/BenchmarksBase.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Benchmarks -{ - public class BenchmarksBase - { - } -} diff --git a/Benchmarks/Container/Create.cs b/Benchmarks/Container/Create.cs index b42be11..53ade24 100644 --- a/Benchmarks/Container/Create.cs +++ b/Benchmarks/Container/Create.cs @@ -1,56 +1,33 @@ using BenchmarkDotNet.Attributes; -using System; -using BenchmarkDotNet.Jobs; +using Benchmarks; #if UNITY_V4 using Microsoft.Practices.Unity; - -namespace Unity.v4 -{ - [SimpleJob(RuntimeMoniker.Net462)] - -#elif UNITY_V5 - -namespace Unity.v5 -{ - [SimpleJob(RuntimeMoniker.Net472)] - #else using Unity.Injection; using Unity.Lifetime; using Unity; +#endif -namespace Unity.v6 +namespace Unity.Benchmarks { - [ShortRunJob(RuntimeMoniker.NetCoreApp50)] - [ShortRunJob(RuntimeMoniker.Net48)] -#endif public partial class Create { private static IUnityContainer Container; + [GlobalSetup] public static void InitializeClass() { Container = new UnityContainer(); } - //[IterationSetup] - //public void IterationSetup() - //{ - //} - - //[IterationCleanup] - //public void IterationCleanup() - //{ - //} - - [Benchmark(Description = "new UnityContainer()"), BenchmarkCategory("new", "UnityContainer")] + [Benchmark(Description = "new UnityContainer()" + BenchmarkBase.VERSION), BenchmarkCategory("new", "UnityContainer")] public object New_UnityContainer() => new UnityContainer(); - [Benchmark(Description = "CreateChildContainer()"), BenchmarkCategory("new", "ChildContainer")] + [Benchmark(Description = "CreateChildContainer()" + BenchmarkBase.VERSION), BenchmarkCategory("new", "ChildContainer")] public object CreateChildContainer() => Container.CreateChildContainer(); } } diff --git a/Container Benchmarks.sln b/Container Benchmarks.sln index 4f74fcc..ccd9c49 100644 --- a/Container Benchmarks.sln +++ b/Container Benchmarks.sln @@ -7,7 +7,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Runner", "Runner\Runner.csp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "Benchmarks\Benchmarks.csproj", "{023E0805-E13F-48F6-B0AC-776E7DAC8E18}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{0F256661-A8DC-49FA-AC8F-512243486A08}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks.Tests", "Tests\Benchmarks.Tests.csproj", "{1D633525-3B20-4D77-81AF-F5311E054C06}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Unity.v4", "Adapters\V4\Unity.v4.csproj", "{82430F08-BA18-4B17-8DBD-EC4BF252B9E8}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Adapters", "Adapters", "{F2EBE6DD-CCF5-4261-8ADD-0C9083182126}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Unity.v5", "Adapters\V5\Unity.v5.csproj", "{DA97DF63-35B3-48D7-BBBA-C0FF6549DF3F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Unity.v6", "Adapters\V6\Unity.v6.csproj", "{D6DB1CC8-73C5-4C59-9CDC-93B420810762}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -19,17 +27,35 @@ Global {925F5BA8-FC9D-45BC-8013-AF95C67ED742}.Debug|Any CPU.Build.0 = Debug|Any CPU {925F5BA8-FC9D-45BC-8013-AF95C67ED742}.Release|Any CPU.ActiveCfg = Release|Any CPU {925F5BA8-FC9D-45BC-8013-AF95C67ED742}.Release|Any CPU.Build.0 = Release|Any CPU - {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Debug|Any CPU.Build.0 = Debug|Any CPU + {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Debug|Any CPU.ActiveCfg = Release|Any CPU + {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Debug|Any CPU.Build.0 = Release|Any CPU {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Release|Any CPU.ActiveCfg = Release|Any CPU {023E0805-E13F-48F6-B0AC-776E7DAC8E18}.Release|Any CPU.Build.0 = Release|Any CPU - {0F256661-A8DC-49FA-AC8F-512243486A08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0F256661-A8DC-49FA-AC8F-512243486A08}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0F256661-A8DC-49FA-AC8F-512243486A08}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D633525-3B20-4D77-81AF-F5311E054C06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1D633525-3B20-4D77-81AF-F5311E054C06}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1D633525-3B20-4D77-81AF-F5311E054C06}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D633525-3B20-4D77-81AF-F5311E054C06}.Release|Any CPU.Build.0 = Release|Any CPU + {82430F08-BA18-4B17-8DBD-EC4BF252B9E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82430F08-BA18-4B17-8DBD-EC4BF252B9E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82430F08-BA18-4B17-8DBD-EC4BF252B9E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82430F08-BA18-4B17-8DBD-EC4BF252B9E8}.Release|Any CPU.Build.0 = Release|Any CPU + {DA97DF63-35B3-48D7-BBBA-C0FF6549DF3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DA97DF63-35B3-48D7-BBBA-C0FF6549DF3F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DA97DF63-35B3-48D7-BBBA-C0FF6549DF3F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DA97DF63-35B3-48D7-BBBA-C0FF6549DF3F}.Release|Any CPU.Build.0 = Release|Any CPU + {D6DB1CC8-73C5-4C59-9CDC-93B420810762}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D6DB1CC8-73C5-4C59-9CDC-93B420810762}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D6DB1CC8-73C5-4C59-9CDC-93B420810762}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D6DB1CC8-73C5-4C59-9CDC-93B420810762}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {82430F08-BA18-4B17-8DBD-EC4BF252B9E8} = {F2EBE6DD-CCF5-4261-8ADD-0C9083182126} + {DA97DF63-35B3-48D7-BBBA-C0FF6549DF3F} = {F2EBE6DD-CCF5-4261-8ADD-0C9083182126} + {D6DB1CC8-73C5-4C59-9CDC-93B420810762} = {F2EBE6DD-CCF5-4261-8ADD-0C9083182126} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {032A4232-BBBB-431E-A478-D3EAA6CA330C} EndGlobalSection diff --git a/Runner/Program.cs b/Runner/Program.cs index dd06e1e..0a443fd 100644 --- a/Runner/Program.cs +++ b/Runner/Program.cs @@ -1,7 +1,7 @@ using BenchmarkDotNet.Running; -using System.IO; -using System.Linq; -using System.Reflection; +using Unity.v4; +using Unity.v5; +using Unity.v6; namespace Unity.Benchmark { @@ -9,12 +9,12 @@ class Program { static void Main(string[] args) { - //BenchmarkSwitcher.FromAssemblies(new[] - //{ - // typeof(Unity.v4.BenchmarksBase).Assembly, - // typeof(Unity.v5.BenchmarksBase).Assembly, - // typeof(Unity.v6.BenchmarksBase).Assembly, - //}).Run(args); + BenchmarkSwitcher.FromAssemblies(new[] + { + typeof(UnityAdapterV4).Assembly, + typeof(UnityAdapterV5).Assembly, + typeof(UnityAdapterV6).Assembly, + }).Run(args); } } } diff --git a/Runner/Runner.csproj b/Runner/Runner.csproj index cb77001..9bc9567 100644 --- a/Runner/Runner.csproj +++ b/Runner/Runner.csproj @@ -17,10 +17,14 @@ - - - - - + + + + + + + + + diff --git a/Tests/Benchmarks.Tests.csproj b/Tests/Benchmarks.Tests.csproj index d37ce42..496f7ab 100644 --- a/Tests/Benchmarks.Tests.csproj +++ b/Tests/Benchmarks.Tests.csproj @@ -2,7 +2,7 @@ ..\..\Container\src\Unity.Container.csproj - net462;net472;net48;net50 + net462;net472;net50 net50 latest diff --git a/Tests/Container/TestCreate.cs b/Tests/Container/TestCreate.cs index 09ec5d6..890d3ac 100644 --- a/Tests/Container/TestCreate.cs +++ b/Tests/Container/TestCreate.cs @@ -1,13 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Benchmark.Tests; -#if UNITY_V4 -using Unity.v4; -#elif UNITY_V5 -using Unity.v5; -#else -using Unity.v6; -#endif - +using Unity.Benchmarks; namespace Continer { From 898fe93e623895aeb96c6d3d7d80500df46fc998 Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Tue, 22 Dec 2020 19:35:54 -0800 Subject: [PATCH 05/14] Linked to container --- Runner/Program.cs | 8 ++++++++ Runner/Runner.csproj | 27 +++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Runner/Program.cs b/Runner/Program.cs index 0a443fd..f0a7274 100644 --- a/Runner/Program.cs +++ b/Runner/Program.cs @@ -1,7 +1,11 @@ using BenchmarkDotNet.Running; +#if STANDALONE using Unity.v4; using Unity.v5; using Unity.v6; +#else +using Benchmarks; +#endif namespace Unity.Benchmark { @@ -11,9 +15,13 @@ static void Main(string[] args) { BenchmarkSwitcher.FromAssemblies(new[] { +#if STANDALONE typeof(UnityAdapterV4).Assembly, typeof(UnityAdapterV5).Assembly, typeof(UnityAdapterV6).Assembly, +#else + typeof(BenchmarkBase).Assembly +#endif }).Run(args); } } diff --git a/Runner/Runner.csproj b/Runner/Runner.csproj index 9bc9567..75a84fc 100644 --- a/Runner/Runner.csproj +++ b/Runner/Runner.csproj @@ -4,6 +4,7 @@ Exe net50 NU1702 + ..\..\Container\src\Unity.Container.csproj @@ -17,14 +18,24 @@ - - - - - - - - + + + + + + + + + STANDALONE;$(DefineConstants) + + + + + + + + + From c6bed1c07c379db014a83be52dd0b56f62c45011 Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Tue, 22 Dec 2020 19:53:44 -0800 Subject: [PATCH 06/14] Cleanup --- Tests/BenchmarkTestBase.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Tests/BenchmarkTestBase.cs b/Tests/BenchmarkTestBase.cs index fd5d700..6133c22 100644 --- a/Tests/BenchmarkTestBase.cs +++ b/Tests/BenchmarkTestBase.cs @@ -2,7 +2,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Linq; -using System.Reflection; namespace Benchmark.Tests { @@ -10,9 +9,14 @@ namespace Benchmark.Tests public class BenchmarkTestBase where TBenchmark : class, new() { + #region Fields + + private static Action IterationSetupAction; + private static Action IterationCleanupAction; protected static TBenchmark Benchmark = new TBenchmark(); - private static Action IterationSetupAction; - private static Action IterationCleanupAction; + + #endregion + #region Constructors From 0996316b7c49ff7213e09eaacc32c3d8aa35b28f Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Tue, 22 Dec 2020 22:13:09 -0800 Subject: [PATCH 07/14] Legacy compatibility --- Benchmarks/Benchmarks.csproj | 18 ++++-------- Benchmarks/Environment.cs | 55 +++++++++++++++++++++++++++++++++++ Directory.Build.props | 49 +++++++++++++++++++++++++++++++ Runner/Runner.csproj | 15 +++++----- Tests/Benchmarks.Tests.csproj | 7 ----- 5 files changed, 117 insertions(+), 27 deletions(-) create mode 100644 Benchmarks/Environment.cs create mode 100644 Directory.Build.props diff --git a/Benchmarks/Benchmarks.csproj b/Benchmarks/Benchmarks.csproj index 08a7245..3924542 100644 --- a/Benchmarks/Benchmarks.csproj +++ b/Benchmarks/Benchmarks.csproj @@ -1,22 +1,16 @@  - - ..\..\Container\src\Unity.Container.csproj - STANDALONE;$(DefineConstants) - net462;net472;net50 - net50 - - - + + UNITY_V4;$(DefineConstants) - $(AssemblyName).V4 + $(AssemblyName).V4 @@ -25,7 +19,7 @@ UNITY_V5;$(DefineConstants) - $(AssemblyName).V5 + $(AssemblyName).V5 @@ -34,7 +28,7 @@ UNITY_V6;$(DefineConstants) - $(AssemblyName).V6 + $(AssemblyName).V6 @@ -44,7 +38,6 @@ UNITY_V6;$(DefineConstants) - $(AssemblyName).Dev @@ -58,6 +51,7 @@ + 8.0 Unity Container Regression Tests Copyright © .NET Foundation and Contributors. All Rights Reserved diff --git a/Benchmarks/Environment.cs b/Benchmarks/Environment.cs new file mode 100644 index 0000000..70e873f --- /dev/null +++ b/Benchmarks/Environment.cs @@ -0,0 +1,55 @@ +// Version + +#if UNITY_V4 +// Unity v4.0.1 +#endif + +#if UNITY_V5 +// Unity v5.11.x +#endif + +#if UNITY_V6 +// Unity v6.x +#endif + + +// Behavior + +#if BEHAVIOR_V4 +// Unity v4.0.1 +#endif + +#if BEHAVIOR_V5 +// Unity v5.11.x +#endif + +#if BEHAVIOR_V6 +// v6.x +#endif + +// .NET Framework + +#if NET5_0 +// Current Framework NET5.0 +#endif +#if NET48 +// Current Framework NET4.8 +#endif +#if NET47 +// Current Framework NET4.7 +#endif +#if NET471 +// Current Framework NET4.7.1 +#endif +#if NET46 +// Current Framework NET4.6 +#endif +#if NET461 +// Current Framework NET4.6.1 +#endif +#if NET462 +// Current Framework NET4.6.2 +#endif +#if NET45 +// Current Framework NET4.5 +#endif diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..b2197fe --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,49 @@ + + + + + ..\..\Container\src\Unity.Container.csproj + ..\..\unity\source\Unity\Src\Unity.csproj + latest + + + + + + + net462 + + + + + + + net472 + + + + + + + net472 + + + + + + + net50 + + + + + + + STANDALONE;$(DefineConstants) + net462;net472;net50 + True + + + + + \ No newline at end of file diff --git a/Runner/Runner.csproj b/Runner/Runner.csproj index 75a84fc..c1b1978 100644 --- a/Runner/Runner.csproj +++ b/Runner/Runner.csproj @@ -2,9 +2,7 @@ Exe - net50 NU1702 - ..\..\Container\src\Unity.Container.csproj @@ -20,19 +18,20 @@ - - - - - - + STANDALONE;$(DefineConstants) + net50 + + + + + diff --git a/Tests/Benchmarks.Tests.csproj b/Tests/Benchmarks.Tests.csproj index 496f7ab..ba6b4eb 100644 --- a/Tests/Benchmarks.Tests.csproj +++ b/Tests/Benchmarks.Tests.csproj @@ -1,11 +1,4 @@  - - - ..\..\Container\src\Unity.Container.csproj - net462;net472;net50 - net50 - latest - From 37f4a6a47e8abba84827c1dc343808f661926e58 Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Tue, 22 Dec 2020 23:26:15 -0800 Subject: [PATCH 08/14] Fixing environment selection --- Benchmarks/Benchmarks.csproj | 38 +++++++++++++-- Benchmarks/Properties/launchSettings.json | 7 +++ Directory.Build.props | 25 +++++----- Runner/Environment.cs | 58 +++++++++++++++++++++++ Runner/Runner.csproj | 56 +++++++++++----------- Tests/Benchmarks.Tests.csproj | 46 +++++++++++++----- 6 files changed, 176 insertions(+), 54 deletions(-) create mode 100644 Benchmarks/Properties/launchSettings.json create mode 100644 Runner/Environment.cs diff --git a/Benchmarks/Benchmarks.csproj b/Benchmarks/Benchmarks.csproj index 3924542..759433f 100644 --- a/Benchmarks/Benchmarks.csproj +++ b/Benchmarks/Benchmarks.csproj @@ -1,5 +1,35 @@  + + + + net462 + + + + + net472 + + + + + net472 + + + + + net50 + + + + + STANDALONE;$(DefineConstants) + net462;net472;net50 + + + + + @@ -13,6 +43,7 @@ $(AssemblyName).V4 + @@ -22,6 +53,7 @@ $(AssemblyName).V5 + @@ -31,6 +63,7 @@ $(AssemblyName).V6 + @@ -38,10 +71,10 @@ UNITY_V6;$(DefineConstants) + $(AssemblyName).V6 - - + @@ -51,7 +84,6 @@ - 8.0 Unity Container Regression Tests Copyright © .NET Foundation and Contributors. All Rights Reserved diff --git a/Benchmarks/Properties/launchSettings.json b/Benchmarks/Properties/launchSettings.json new file mode 100644 index 0000000..05fb17f --- /dev/null +++ b/Benchmarks/Properties/launchSettings.json @@ -0,0 +1,7 @@ +{ + "profiles": { + "Benchmarks": { + "commandName": "Project" + } + } +} \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index b2197fe..a6550ce 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,45 +4,46 @@ ..\..\Container\src\Unity.Container.csproj ..\..\unity\source\Unity\Src\Unity.csproj - latest + 9.0 - + + - + - net462 + LEGACY - net472 + MASTER - net472 - + DEVELOP + + - net50 + LATEST - STANDALONE;$(DefineConstants) - net462;net472;net50 - True - + STANDALONE + + diff --git a/Runner/Environment.cs b/Runner/Environment.cs new file mode 100644 index 0000000..fe00293 --- /dev/null +++ b/Runner/Environment.cs @@ -0,0 +1,58 @@ +// Version + +#if UNITY_V4 +// Unity v4.0.1 +#endif + +#if UNITY_V5 +// Unity v5.11.x +#endif + +#if UNITY_V6 +// Unity v6.x +#endif + + +// Behavior + +#if BEHAVIOR_V4 +// Unity v4.0.1 +#endif + +#if BEHAVIOR_V5 +// Unity v5.11.x +#endif + +#if BEHAVIOR_V6 +// v6.x +#endif + +// .NET Framework + +#if NET5_0 +// Current Framework NET5.0 +#endif +#if NET48 +// Current Framework NET4.8 +#endif +#if NET47 +// Current Framework NET4.7 +#endif +#if NET471 +// Current Framework NET4.7.1 +#endif +#if NET472 +// Current Framework NET4.7.2 +#endif +#if NET46 +// Current Framework NET4.6 +#endif +#if NET461 +// Current Framework NET4.6.1 +#endif +#if NET462 +// Current Framework NET4.6.2 +#endif +#if NET45 +// Current Framework NET4.5 +#endif diff --git a/Runner/Runner.csproj b/Runner/Runner.csproj index c1b1978..d0bad5a 100644 --- a/Runner/Runner.csproj +++ b/Runner/Runner.csproj @@ -1,40 +1,40 @@  - - Exe - NU1702 - + + Exe + NU1702 + + net50 + - - - - - + + + + + - - - - + + + + - - - STANDALONE;$(DefineConstants) - net50 - - - - - - + + + STANDALONE;$(DefineConstants) + + + + + + - - - + + + - - + diff --git a/Tests/Benchmarks.Tests.csproj b/Tests/Benchmarks.Tests.csproj index ba6b4eb..6134808 100644 --- a/Tests/Benchmarks.Tests.csproj +++ b/Tests/Benchmarks.Tests.csproj @@ -1,5 +1,35 @@  + + + + net462 + + + + + net472 + + + + + net472 + + + + + net50 + + + + + STANDALONE;$(DefineConstants) + net462;net472;net50 + + + + + @@ -10,17 +40,6 @@ UNITY_V4;$(DefineConstants) - - - - - - - - Unity Container Regression Tests - Copyright © .NET Foundation and Contributors. All Rights Reserved - - @@ -31,4 +50,9 @@ + + Unity Container Regression Tests + Copyright © .NET Foundation and Contributors. All Rights Reserved + + \ No newline at end of file From 17e6174529cf25a03cd77a11df28f267d6f831d9 Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Tue, 22 Dec 2020 23:31:53 -0800 Subject: [PATCH 09/14] Compatibility --- Runner/Runner.csproj | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/Runner/Runner.csproj b/Runner/Runner.csproj index d0bad5a..d198518 100644 --- a/Runner/Runner.csproj +++ b/Runner/Runner.csproj @@ -4,7 +4,6 @@ Exe NU1702 - net50 @@ -18,22 +17,49 @@ - - + - STANDALONE;$(DefineConstants) + net462 - - - + - + + + net472 + + + + + + + + net472 + + + + + net50 + + + + + + + + net50 + STANDALONE;$(DefineConstants) + + + + + + From bdd3fee82b2b726e46d5f162a5cf3250b20e493c Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Wed, 23 Dec 2020 12:10:59 -0800 Subject: [PATCH 10/14] More tests --- Benchmarks/Benchmarks.csproj | 29 ++++++---- Benchmarks/Pipeline/Create.cs | 22 ++++++++ Benchmarks/Pipeline/Setup.V4.cs | 67 +++++++++++++++++++++++ Benchmarks/Pipeline/Setup.cs | 26 +++++++++ Benchmarks/Properties/launchSettings.json | 7 --- Tests/Pipeline/Create.cs | 17 ++++++ Tests/Pipeline/Setup.cs | 11 ++++ 7 files changed, 160 insertions(+), 19 deletions(-) create mode 100644 Benchmarks/Pipeline/Create.cs create mode 100644 Benchmarks/Pipeline/Setup.V4.cs create mode 100644 Benchmarks/Pipeline/Setup.cs delete mode 100644 Benchmarks/Properties/launchSettings.json create mode 100644 Tests/Pipeline/Create.cs create mode 100644 Tests/Pipeline/Setup.cs diff --git a/Benchmarks/Benchmarks.csproj b/Benchmarks/Benchmarks.csproj index 759433f..1b97fa0 100644 --- a/Benchmarks/Benchmarks.csproj +++ b/Benchmarks/Benchmarks.csproj @@ -31,7 +31,7 @@ - + @@ -43,7 +43,7 @@ $(AssemblyName).V4 - + @@ -53,7 +53,7 @@ $(AssemblyName).V5 - + @@ -63,7 +63,7 @@ $(AssemblyName).V6 - + @@ -75,17 +75,22 @@ - + + + + + + - - - + + + - - Unity Container Regression Tests - Copyright © .NET Foundation and Contributors. All Rights Reserved - + + Unity Container Regression Tests + Copyright © .NET Foundation and Contributors. All Rights Reserved + \ No newline at end of file diff --git a/Benchmarks/Pipeline/Create.cs b/Benchmarks/Pipeline/Create.cs new file mode 100644 index 0000000..8460f79 --- /dev/null +++ b/Benchmarks/Pipeline/Create.cs @@ -0,0 +1,22 @@ +using BenchmarkDotNet.Attributes; +using Benchmarks; +#if UNITY_V4 +using Microsoft.Practices.Unity; +#else +using Unity.Injection; +using Unity.Lifetime; +using Unity; +#endif + +namespace Unity.Benchmarks +{ + public partial class PipelineBenchmarks + { + [Benchmark(Description = "Create Pipeline for Unknown" + BenchmarkBase.VERSION), BenchmarkCategory("Pipeline", "Create")] + public object Pipeline_Create_Unknown() => Container.Resolve(typeof(object)); + + + [Benchmark(Description = "Create Pipeline for Registered" + BenchmarkBase.VERSION), BenchmarkCategory("Pipeline", "Create")] + public object Pipeline_Create_Registered() => Container.Resolve(typeof(object)); + } +} diff --git a/Benchmarks/Pipeline/Setup.V4.cs b/Benchmarks/Pipeline/Setup.V4.cs new file mode 100644 index 0000000..344df13 --- /dev/null +++ b/Benchmarks/Pipeline/Setup.V4.cs @@ -0,0 +1,67 @@ +using BenchmarkDotNet.Attributes; +using System.Linq; +#if UNITY_V4 +using Microsoft.Practices.Unity.ObjectBuilder; +using Microsoft.Practices.ObjectBuilder2; +using Microsoft.Practices.Unity; +#else +using Unity.Injection; +using Unity.Lifetime; +using Unity; +#endif + +namespace Unity.Benchmarks +{ + public class PipelineSpyExtension : UnityContainerExtension + { + protected override void Initialize() + { + // Unity v4 did not offer any way of replacing built in strategies + // The only way to do it is to clear and repopulate + + // Get an array of all strategies. + var strategies = Context.Strategies.MakeStrategyChain() + .ToArray(); + // Clear the chain + Context.Strategies.Clear(); + + // Repopulate main strategy chain, replacing the last one + // Main strategy chain + Context.Strategies.Add(strategies[0], UnityBuildStage.TypeMapping); + Context.Strategies.Add(strategies[1], UnityBuildStage.Lifetime); + Context.Strategies.Add(strategies[2], UnityBuildStage.Lifetime); + Context.Strategies.Add(strategies[3], UnityBuildStage.Creation); + + Context.Strategies.Add(new PipelineSpyStrategy(), UnityBuildStage.Creation); + } + } + + public class PipelineSpyStrategy : BuildPlanStrategy + { + /// + /// Override default build plan with this one + /// + public override void PreBuildUp(IBuilderContext context) + { + IPolicyList buildPlanLocation; + + var plan = context.Policies.Get(context.BuildKey, out buildPlanLocation); + if (plan == null /*|| plan is OverriddenBuildPlanMarkerPolicy*/) + { + IPolicyList creatorLocation; + + var planCreator = context.Policies.Get(context.BuildKey, out creatorLocation); + if (planCreator != null) + { + plan = planCreator.CreatePlan(context, context.BuildKey); + // Disable pipeline save so it builds it every time + //(buildPlanLocation ?? creatorLocation).Set(plan, context.BuildKey); + } + } + if (plan != null) + { + plan.BuildUp(context); + } + } + } +} diff --git a/Benchmarks/Pipeline/Setup.cs b/Benchmarks/Pipeline/Setup.cs new file mode 100644 index 0000000..4572cc3 --- /dev/null +++ b/Benchmarks/Pipeline/Setup.cs @@ -0,0 +1,26 @@ +using BenchmarkDotNet.Attributes; +#if UNITY_V4 +using Microsoft.Practices.Unity; +#else +using Unity.Injection; +using Unity.Lifetime; +using Unity; +#endif + +namespace Unity.Benchmarks +{ + public partial class PipelineBenchmarks + { + private static IUnityContainer Container; + + + [GlobalSetup] + public static void InitializeClass() + { + var unity = new UnityContainer() + .AddExtension(new PipelineSpyExtension()); + + Container = unity; + } + } +} diff --git a/Benchmarks/Properties/launchSettings.json b/Benchmarks/Properties/launchSettings.json deleted file mode 100644 index 05fb17f..0000000 --- a/Benchmarks/Properties/launchSettings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "profiles": { - "Benchmarks": { - "commandName": "Project" - } - } -} \ No newline at end of file diff --git a/Tests/Pipeline/Create.cs b/Tests/Pipeline/Create.cs new file mode 100644 index 0000000..51bf433 --- /dev/null +++ b/Tests/Pipeline/Create.cs @@ -0,0 +1,17 @@ +using BenchmarkDotNet.Attributes; +using Benchmarks; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Pipeline +{ + public partial class TestPipelineBenchmarks + { + [TestMethod] + public void Pipeline_Create_Unknown() + => Assert.IsNotNull(Benchmark.Pipeline_Create_Unknown()); + + [TestMethod] + public void Pipeline_Create_Registered() + => Assert.IsNotNull(Benchmark.Pipeline_Create_Registered()); + } +} diff --git a/Tests/Pipeline/Setup.cs b/Tests/Pipeline/Setup.cs new file mode 100644 index 0000000..808c9ad --- /dev/null +++ b/Tests/Pipeline/Setup.cs @@ -0,0 +1,11 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Benchmark.Tests; +using Unity.Benchmarks; + +namespace Pipeline +{ + [TestClass] + public partial class TestPipelineBenchmarks : BenchmarkTestBase + { + } +} From 7df9f971b1bdd8f62d8d7b7f54aee4ae1d6687f2 Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Wed, 23 Dec 2020 12:40:48 -0800 Subject: [PATCH 11/14] Added v5 handling --- Benchmarks/Pipeline/Setup.V4.cs | 23 +++++----- Benchmarks/Pipeline/Setup.V5.cs | 79 +++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 Benchmarks/Pipeline/Setup.V5.cs diff --git a/Benchmarks/Pipeline/Setup.V4.cs b/Benchmarks/Pipeline/Setup.V4.cs index 344df13..8c6548f 100644 --- a/Benchmarks/Pipeline/Setup.V4.cs +++ b/Benchmarks/Pipeline/Setup.V4.cs @@ -1,17 +1,14 @@ -using BenchmarkDotNet.Attributes; -using System.Linq; -#if UNITY_V4 +using System.Linq; using Microsoft.Practices.Unity.ObjectBuilder; using Microsoft.Practices.ObjectBuilder2; using Microsoft.Practices.Unity; -#else -using Unity.Injection; -using Unity.Lifetime; -using Unity; -#endif namespace Unity.Benchmarks { + /// + /// An extension to install custom strategy that disables + /// saving of created build plan + /// public class PipelineSpyExtension : UnityContainerExtension { protected override void Initialize() @@ -36,17 +33,19 @@ protected override void Initialize() } } + /// + /// Unity v5 uses to create and save + /// a build plan for each created type + /// public class PipelineSpyStrategy : BuildPlanStrategy { - /// - /// Override default build plan with this one - /// + // Override default implementation public override void PreBuildUp(IBuilderContext context) { IPolicyList buildPlanLocation; var plan = context.Policies.Get(context.BuildKey, out buildPlanLocation); - if (plan == null /*|| plan is OverriddenBuildPlanMarkerPolicy*/) + if (plan == null) { IPolicyList creatorLocation; diff --git a/Benchmarks/Pipeline/Setup.V5.cs b/Benchmarks/Pipeline/Setup.V5.cs new file mode 100644 index 0000000..b431ce7 --- /dev/null +++ b/Benchmarks/Pipeline/Setup.V5.cs @@ -0,0 +1,79 @@ +using System; +using Unity.Strategies; +using Unity.Extension; +using Unity.Policy; +using Unity.Builder; +using Unity.Resolution; +using Unity.Registration; +using System.Globalization; + +namespace Unity.Benchmarks +{ + /// + /// An extension to install custom strategy that disables + /// saving of created build plan + /// + public class PipelineSpyExtension : UnityContainerExtension + { + protected override void Initialize() + { + Context.Strategies.Add(new PipelineSpyStrategy(), UnityBuildStage.PreCreation); + } + } + + /// + /// Unity v5 uses to create and save + /// a build plan for each created type + /// + public class PipelineSpyStrategy : BuildPlanStrategy + { + // Override default implementation + public override void PreBuildUp(ref BuilderContext context) + { + var resolver = context.Registration.Get>() ?? (ResolveDelegate) + GetGeneric(ref context, typeof(ResolveDelegate)); + + if (null == resolver) + { +#if NETCOREAPP1_0 || NETSTANDARD1_0 + if (!(context.Registration is ContainerRegistration) && context.RegistrationType.GetTypeInfo().IsGenericTypeDefinition) +#else + if (!(context.Registration is ContainerRegistration) && context.RegistrationType.IsGenericTypeDefinition) +#endif + { + throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, + "The type {0} is an open generic type. An open generic type cannot be resolved.", + context.RegistrationType.FullName), new Exception()); + } + else if (context.Type.IsArray && context.Type.GetArrayRank() > 1) + { + var message = $"Invalid array {context.Type}. Only arrays of rank 1 are supported"; + throw new ArgumentException(message, new Exception()); + } + + var factory = context.Registration.Get() ?? (ResolveDelegateFactory)( + context.Get(context.Type, UnityContainer.All, typeof(ResolveDelegateFactory)) ?? + GetGeneric(ref context, typeof(ResolveDelegateFactory)) ?? + context.Get(null, null, typeof(ResolveDelegateFactory))); + + if (null != factory) + { + resolver = factory(ref context); + + // Disable saving, force creation every time + // context.Registration.Set(typeof(ResolveDelegate), resolver); + context.Existing = resolver(ref context); + } + else + throw new ResolutionFailedException(context.Type, context.Name, $"Failed to find Resolve Delegate Factory for Type {context.Type}"); + } + else + { + context.Existing = resolver(ref context); + } + + // Prevent further processing + context.BuildComplete = true; + } + } +} From 2825a7966f971127ae89b0a38aad4589ffee7704 Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Wed, 23 Dec 2020 12:41:18 -0800 Subject: [PATCH 12/14] Added v5 setup --- Benchmarks/Benchmarks.csproj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Benchmarks/Benchmarks.csproj b/Benchmarks/Benchmarks.csproj index 1b97fa0..dc18c29 100644 --- a/Benchmarks/Benchmarks.csproj +++ b/Benchmarks/Benchmarks.csproj @@ -46,7 +46,8 @@ - + + UNITY_V5;$(DefineConstants) @@ -81,6 +82,7 @@ + From f3ffd771e213331d95cd24fe282cdf7c1f98a54a Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Wed, 23 Dec 2020 14:11:44 -0800 Subject: [PATCH 13/14] V6 compatibility --- Benchmarks/Benchmarks.csproj | 3 ++- Benchmarks/Pipeline/Setup.V6.cs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 Benchmarks/Pipeline/Setup.V6.cs diff --git a/Benchmarks/Benchmarks.csproj b/Benchmarks/Benchmarks.csproj index dc18c29..a546847 100644 --- a/Benchmarks/Benchmarks.csproj +++ b/Benchmarks/Benchmarks.csproj @@ -82,7 +82,8 @@ - + + diff --git a/Benchmarks/Pipeline/Setup.V6.cs b/Benchmarks/Pipeline/Setup.V6.cs new file mode 100644 index 0000000..df8f1bb --- /dev/null +++ b/Benchmarks/Pipeline/Setup.V6.cs @@ -0,0 +1,17 @@ +using System; +using Unity.Extension; + +namespace Unity.Benchmarks +{ + /// + /// An extension to install custom strategy that disables + /// saving of created build plan + /// + public class PipelineSpyExtension : UnityContainerExtension + { + protected override void Initialize() + { + //Context.Strategies.Add(new PipelineSpyStrategy(), UnityBuildStage.PreCreation); + } + } +} From bf15e498c9d69dfd1a8be0acb46455c2beaaa46e Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Thu, 24 Dec 2020 19:58:39 -0800 Subject: [PATCH 14/14] wip --- Benchmarks/Pipeline/Create.cs | 2 +- Benchmarks/Pipeline/Setup.cs | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Benchmarks/Pipeline/Create.cs b/Benchmarks/Pipeline/Create.cs index 8460f79..9e45d30 100644 --- a/Benchmarks/Pipeline/Create.cs +++ b/Benchmarks/Pipeline/Create.cs @@ -17,6 +17,6 @@ public partial class PipelineBenchmarks [Benchmark(Description = "Create Pipeline for Registered" + BenchmarkBase.VERSION), BenchmarkCategory("Pipeline", "Create")] - public object Pipeline_Create_Registered() => Container.Resolve(typeof(object)); + public object Pipeline_Create_Registered() => Container.Resolve(typeof(Service)); } } diff --git a/Benchmarks/Pipeline/Setup.cs b/Benchmarks/Pipeline/Setup.cs index 4572cc3..8fc41b8 100644 --- a/Benchmarks/Pipeline/Setup.cs +++ b/Benchmarks/Pipeline/Setup.cs @@ -13,14 +13,22 @@ public partial class PipelineBenchmarks { private static IUnityContainer Container; - [GlobalSetup] public static void InitializeClass() { - var unity = new UnityContainer() - .AddExtension(new PipelineSpyExtension()); - - Container = unity; + Container = new UnityContainer() + .AddExtension(new PipelineSpyExtension()) + .RegisterType(); } } + + + #region Test Data + + public class Service + { + + } + + #endregion }