зеркало из
1
0
Форкнуть 0

Fix benchmarks and move them to benchmarks directory (#593)

This commit is contained in:
Pavel Krymets 2017-10-11 09:36:26 -07:00 коммит произвёл GitHub
Родитель 014749e55c
Коммит 5a549d6a1a
7 изменённых файлов: 25 добавлений и 15 удалений

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

@ -39,7 +39,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DI.Specification.Tests", "src\DI.Specification.Tests\DI.Specification.Tests.csproj", "{B9395B0F-E8E3-4913-BABF-E71A76F21231}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DI.Performance", "test\DI.Performance\DI.Performance.csproj", "{2AB56E17-8ADC-4763-B298-79BFECC351A8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DI.Performance", "benchmarks\DI.Performance\DI.Performance.csproj", "{2AB56E17-8ADC-4763-B298-79BFECC351A8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{483CFA4B-18DB-404D-BCA0-E39E6734733F}"
ProjectSection(SolutionItems) = preProject

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

@ -19,9 +19,14 @@ namespace Microsoft.Extensions.DependencyInjection.Performance
private IServiceProvider _serviceScopeFactoryProvider;
private IServiceProvider _serviceScope;
private IServiceProvider _emptyEnumerable;
private ServiceProviderMode _mode;
[Params(ServiceProviderMode.Compiled, ServiceProviderMode.Dynamic, ServiceProviderMode.Runtime)]
internal ServiceProviderMode Mode { get; set; }
[Params("Compiled", "Dynamic", "Runtime")]
public string Mode {
set {
_mode = Enum.Parse<ServiceProviderMode>(value);
}
}
[Benchmark(Baseline = true, OperationsPerInvoke = OperationsPerInvoke)]
public void NoDI()
@ -42,7 +47,7 @@ namespace Microsoft.Extensions.DependencyInjection.Performance
services.AddTransient<C>();
_transientSp = services.BuildServiceProvider(new ServiceProviderOptions()
{
Mode = Mode
Mode = _mode
});
}
@ -65,7 +70,7 @@ namespace Microsoft.Extensions.DependencyInjection.Performance
services.AddScoped<C>();
_scopedSp = services.BuildServiceProvider(new ServiceProviderOptions()
{
Mode = Mode
Mode = _mode
}).CreateScope();
}
@ -88,7 +93,7 @@ namespace Microsoft.Extensions.DependencyInjection.Performance
services.AddSingleton<C>();
_singletonSp = services.BuildServiceProvider(new ServiceProviderOptions()
{
Mode = Mode
Mode = _mode
});
}
@ -107,7 +112,7 @@ namespace Microsoft.Extensions.DependencyInjection.Performance
{
_serviceScope = new ServiceCollection().BuildServiceProvider(new ServiceProviderOptions()
{
Mode = Mode
Mode = _mode
});
}
@ -125,7 +130,7 @@ namespace Microsoft.Extensions.DependencyInjection.Performance
{
_serviceScopeFactoryProvider = new ServiceCollection().BuildServiceProvider(new ServiceProviderOptions()
{
Mode = Mode
Mode = _mode
});
}
@ -143,7 +148,7 @@ namespace Microsoft.Extensions.DependencyInjection.Performance
{
_emptyEnumerable = new ServiceCollection().BuildServiceProvider(new ServiceProviderOptions()
{
Mode = Mode
Mode = _mode
});
}

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

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

@ -16,9 +16,14 @@ namespace Microsoft.Extensions.DependencyInjection.Performance
private ServiceCollection _transientServices;
private ServiceCollection _scopedServices;
private ServiceCollection _singletonServices;
private ServiceProviderMode _mode;
[Params(ServiceProviderMode.Compiled, ServiceProviderMode.Dynamic, ServiceProviderMode.Runtime)]
internal ServiceProviderMode Mode { get; set; }
[Params("Compiled", "Dynamic", "Runtime")]
public string Mode {
set {
_mode = Enum.Parse<ServiceProviderMode>(value);
}
}
[Benchmark(Baseline = true)]
public void NoDI()
@ -41,7 +46,7 @@ namespace Microsoft.Extensions.DependencyInjection.Performance
{
_transientSp = _transientServices.BuildServiceProvider(new ServiceProviderOptions()
{
Mode = Mode
Mode = _mode
});
}
@ -59,7 +64,7 @@ namespace Microsoft.Extensions.DependencyInjection.Performance
{
_transientSp = _transientServices.BuildServiceProvider(new ServiceProviderOptions()
{
Mode = Mode
Mode = _mode
});
var temp = _transientSp.GetService<A>();
temp.Foo();
@ -79,7 +84,7 @@ namespace Microsoft.Extensions.DependencyInjection.Performance
{
_scopedSp = _scopedServices.BuildServiceProvider(new ServiceProviderOptions()
{
Mode = Mode
Mode = _mode
}).CreateScope();
var temp = _scopedSp.ServiceProvider.GetService<A>();
temp.Foo();
@ -99,7 +104,7 @@ namespace Microsoft.Extensions.DependencyInjection.Performance
{
_singletonSp = _singletonServices.BuildServiceProvider(new ServiceProviderOptions()
{
Mode = Mode
Mode = _mode
});
var temp = _singletonSp.GetService<A>();
temp.Foo();