1
0
Форкнуть 0

Merge pull request #2 from PureWeen/ios_add

Add more resolution and some additional IoC features
This commit is contained in:
Javier Suárez 2020-06-02 14:15:52 +02:00 коммит произвёл GitHub
Родитель 470c70386f c61ba5119e
Коммит 3e7443d80d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 167 добавлений и 49 удалений

Просмотреть файл

@ -16,7 +16,7 @@
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v8.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
@ -50,10 +50,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac">
<Version>4.9.2</Version>
<Version>5.2.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>3.1.4</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.8</Version>
<Version>6.2.10</Version>
</PackageReference>
<PackageReference Include="TinyIoC">
<Version>1.3.0</Version>
@ -61,20 +64,9 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Unity">
<Version>5.10.3</Version>
<Version>5.11.6</Version>
</PackageReference>
<PackageReference Include="Xamarin.Android.Support.Annotations">
<Version>28.0.0.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.Android.Support.Compat">
<Version>28.0.0.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="3.6.0.344457" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.772" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />

Просмотреть файл

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.IoCPerformance">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="27" />
<application android:label="IoCPerformance.Android"></application>
</manifest>
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
<application android:label="IoCPerformance.Android"></application>
</manifest>

Просмотреть файл

@ -144,7 +144,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac">
<Version>4.9.2</Version>
<Version>5.2.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>3.1.4</Version>
</PackageReference>
<PackageReference Include="TinyIoC">
<Version>1.3.0</Version>
@ -152,10 +155,10 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Unity">
<Version>5.10.3</Version>
<Version>5.11.6</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="3.6.0.344457" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.8" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.772" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IoCPerformance\IoCPerformance.csproj">

Просмотреть файл

@ -149,10 +149,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac">
<Version>4.9.2</Version>
<Version>5.2.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>3.1.4</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.8</Version>
<Version>6.2.10</Version>
</PackageReference>
<PackageReference Include="TinyIoC">
<Version>1.3.0</Version>
@ -160,9 +163,9 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Unity">
<Version>5.10.3</Version>
<Version>5.11.6</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="3.6.0.344457" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.772" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>

Просмотреть файл

@ -11,6 +11,8 @@ namespace IoCPerformance.IoC
private static ContainerBuilder _builder { get; set; }
private static IContainer _container { get; set; }
ILifetimeScope _scope;
public AutofacPerformance(int numberOfTests)
{
_numberOfTests = numberOfTests;
@ -20,22 +22,25 @@ namespace IoCPerformance.IoC
public void Registration()
{
for (int x = 0; x < _numberOfTests; x++)
for (int x = 0; x < _numberOfTests + 1; x++)
{
_builder.RegisterType<TestService>().As<ITestService>().Named<TestService>(string.Format("Class{0}", x));
}
_container = _builder.Build();
_scope = _container.BeginLifetimeScope();
}
public void FirstResolve()
{
_scope.ResolveNamed<TestService>(string.Format("Class{0}", "0"));
}
public void Resolve()
{
using (var scope = _container.BeginLifetimeScope())
{
for (int x = 1; x < _numberOfTests + 1; x++)
{
for (int x = 0; x < _numberOfTests; x++)
{
scope.ResolveNamed<TestService>(string.Format("Class{0}", x));
}
_scope.ResolveNamed<TestService>(string.Format("Class{0}", x));
}
}
}

Просмотреть файл

@ -5,5 +5,7 @@
void Registration();
void Resolve();
void FirstResolve();
}
}

Просмотреть файл

@ -0,0 +1,39 @@
using IoCPerformance.IoC.Base;
using IoCPerformance.Services.Test;
using Unity;
using Xamarin.Forms;
namespace IoCPerformance.IoC
{
public class DependencyResolver : IPerformance
{
private readonly int _numberOfTests;
public DependencyResolver(int numberOfTests)
{
_numberOfTests = numberOfTests;
}
public void FirstResolve()
{
DependencyService.Get<ITestService>(DependencyFetchTarget.NewInstance);
}
public void Registration()
{
for (int x = 0; x < _numberOfTests; x++)
{
DependencyService.Register<ITestService, TestService>();
}
}
public void Resolve()
{
for (int x = 0; x < _numberOfTests; x++)
{
var returnMe = DependencyService.Get<ITestService>(DependencyFetchTarget.NewInstance);
}
}
}
}

Просмотреть файл

@ -0,0 +1,41 @@
using IoCPerformance.IoC.Base;
using IoCPerformance.Services.Test;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace IoCPerformance.IoC
{
public class NetCoreServiceProvider : IPerformance
{
private int _numberOfTests;
IServiceProvider _serviceProvider;
public NetCoreServiceProvider(int numberOfTests)
{
_numberOfTests = numberOfTests;
}
public void Registration()
{
for (int x = 0; x < _numberOfTests; x++)
{
ServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddTransient<ITestService, TestService>();
_serviceProvider = serviceCollection.BuildServiceProvider();
}
}
public void FirstResolve()
{
var returnMe = _serviceProvider.GetService<ITestService>();
}
public void Resolve()
{
for (int x = 0; x < _numberOfTests; x++)
{
var returnMe = _serviceProvider.GetService<ITestService>();
}
}
}
}

Просмотреть файл

@ -21,15 +21,20 @@ namespace IoCPerformance.IoC
public void Registration()
{
for (int i = 0; i < _numberOfTests; i++)
for (int i = 0; i < _numberOfTests + 1; i++)
{
_mutableContainer.Register(() => new TestService(), contract: $"Class{i}");
}
}
public void FirstResolve()
{
_container.GetService<TestService>($"Class0");
}
public void Resolve()
{
for (int i = 0; i < _numberOfTests; i++)
for (int i = 1; i < _numberOfTests + 1; i++)
{
_container.GetService<TestService>($"Class{i}");
}

Просмотреть файл

@ -18,15 +18,20 @@ namespace IoCPerformance.IoC
public void Registration()
{
for (int x = 0; x < _numberOfTests; x++)
for (int x = 0; x < _numberOfTests + 1; x++)
{
_container.Register<TestService>(string.Format("Class{0}", x));
}
}
public void FirstResolve()
{
_container.Resolve<TestService>(string.Format("Class{0}", "0"));
}
public void Resolve()
{
for (int x = 0; x < _numberOfTests; x++)
for (int x = 1; x < _numberOfTests + 1; x++)
{
_container.Resolve<TestService>(string.Format("Class{0}", x));
}

Просмотреть файл

@ -18,15 +18,20 @@ namespace IoCPerformance.IoC
public void Registration()
{
for (int x = 0; x < _numberOfTests; x++)
for (int x = 0; x < _numberOfTests + 1; x++)
{
_unityContainer.RegisterType<ITestService, TestService>(string.Format("Class{0}", x));
}
}
public void FirstResolve()
{
_unityContainer.Resolve<ITestService>(string.Format("Class{0}", "0"));
}
public void Resolve()
{
for (int x = 0; x < _numberOfTests; x++)
for (int x = 1; x < _numberOfTests + 1; x++)
{
_unityContainer.Resolve<ITestService>(string.Format("Class{0}", x));
}

Просмотреть файл

@ -10,15 +10,16 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.2" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.8" />
<PackageReference Include="Splat" Version="7.2.1" />
<PackageReference Include="Autofac" Version="5.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.10" />
<PackageReference Include="Splat" Version="9.4.5" />
<PackageReference Include="TinyIoC" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Unity" Version="5.10.3" />
<PackageReference Include="Xamarin.Forms" Version="3.6.0.344457" />
<PackageReference Include="Unity" Version="5.11.6" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.772" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -28,22 +28,31 @@ namespace IoCPerformance.ViewModels
private void ExecuteTest()
{
NumberOfTests = 25;
NumberOfTests = 5000;
_watch = new Stopwatch();
AutofacPerformance autofacPerformanceTest = new AutofacPerformance(NumberOfTests);
TinyIocPerformance tinyIocPerformanceTest = new TinyIocPerformance(NumberOfTests);
UnityPerformance unityPerformanceTest = new UnityPerformance(NumberOfTests);
SplatPerformance splatPerformance = new SplatPerformance(NumberOfTests);
DependencyResolver dependencyResolver = new DependencyResolver(NumberOfTests);
NetCoreServiceProvider netCoreServiceProvider = new NetCoreServiceProvider(NumberOfTests);
RunTests(autofacPerformanceTest, "AutoFac");
RunTests(tinyIocPerformanceTest, "TinyIoC");
RunTests(unityPerformanceTest, "Unity");
RunTests(splatPerformance, "Splat");
RunTests(dependencyResolver, "Xamarin.Forms Dependency Resolver");
RunTests(netCoreServiceProvider, "Microsoft.Net Dependency Injection");
}
private void RunTests(IPerformance performanceTest, string testName)
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
try
{
Output += string.Format("Starting performance test for {0}", testName) + Environment.NewLine;
@ -52,13 +61,21 @@ namespace IoCPerformance.ViewModels
performanceTest.Registration();
Output += string.Format("IOC Registration Time for {0} tests: {1} ms", NumberOfTests, _watch.Elapsed.Milliseconds.ToString()) + Environment.NewLine;
Output += string.Format("Avg. IOC Registration Time for {0} tests: {1} ms", NumberOfTests, ((double)_watch.Elapsed.Milliseconds / (double)NumberOfTests).ToString()) + Environment.NewLine;
_watch.Restart();
performanceTest.FirstResolve();
Output += string.Format("IOC First Resolution Time: {0} ms", _watch.Elapsed.Milliseconds.ToString()) + Environment.NewLine;
_watch.Restart();
performanceTest.Resolve();
Output += string.Format("IOC Resolution Time for {0} tests: {1} ms", NumberOfTests, _watch.Elapsed.Milliseconds.ToString()) + Environment.NewLine;
Output += string.Format("Total IOC Resolution Time for {0} tests: {1} ms", NumberOfTests, _watch.Elapsed.Milliseconds) + Environment.NewLine;
Output += string.Format("Avg. IOC Resolution Time for {0} tests: {1} ms", NumberOfTests, ((double)_watch.Elapsed.Milliseconds / (double)NumberOfTests).ToString()) + Environment.NewLine;
}
finally
{