-
Notifications
You must be signed in to change notification settings - Fork 280
Adds Microsoft.Extensions.* performance tests with history #1362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
1690290
Reorganize source code
0194014
Merge branch 'release/2.1' into release/2.2
814a3b0
Merge branch 'release/2.2'
f240aca
Reorganize source code in preparation to move into aspnet/Extensions
5c3d7d7
Reorganize source code in preparation to move into aspnet/Extensions
4548ba5
Reorganize source code in preparation to move into aspnet/Extensions
4ee3c9e
Merge the source code from aspnet/DependencyInjection release/2.1
b7ccbb6
Merge branch 'release/2.1' into release/2.2
b52a855
Merge branch 'release/2.2'
2c88e33
Reorganize source code in preparation to move into aspnet/Extensions
d746978
Merge branch 'release/2.2'
893cb96
Reorganize source code in preparation to move into aspnet/Extensions
14a2e29
Use the SharedSourceRoot variable in project files
d58cbe8
Merge the source code from aspnet/HttpClientFactory into this repo
7bc945d
Merge branch 'release/2.1' into release/2.2
bfc6f92
Merge branch 'release/2.2'
0d0378b
Allow caching of IEnumerable services (dotnet/Extensions#575)
pakrym c7451bd
Reduce event source logger allocations (dotnet/Extensions#870)
pakrym 89bed04
Use Arcade (dotnet/Extensions#586)
ryanbrandenburg 242f3a1
Cleanup conversion to Arcade (dotnet/Extensions#1014)
natemcmaster dd2d8d7
Shrink StringValues (dotnet/Extensions#1283)
benaadams 32e853b
Disable transitive project references in test projects (dotnet/Extens…
natemcmaster fc1df90
Fix HTTP client benchmarks
bdac559
Add typed client creation benchmark
0afd56b
Support netcoreapp3.1 TFM (dotnet/Extensions#2336)
c303731
Normalize all file headers to the expected Apache 2.0 license
sharwell 8ffa5b7
Switch file headers to the MIT license
sharwell 4622cb5
Merge branch 'master' of https://github.com/dotnet/performance into 4in1
maryamariyan 48ba3c4
Moves Microsoft.Extensions.* perf tests over
maryamariyan fe1da91
Using the Open key to fully sign assembly
maryamariyan 32a0653
Apply suggestions from code review
maryamariyan 4caa9bd
Fix compile + other feedback
maryamariyan 6f0a642
Apply suggestions from code review
adamsitnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...s/micro/libraries/Microsoft.Extensions.DependencyInjection/ActivatorUtilitiesBenchmark.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using BenchmarkDotNet.Attributes; | ||
using MicroBenchmarks; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
[BenchmarkCategory(Categories.Libraries)] | ||
public class ActivatorUtilitiesBenchmark | ||
{ | ||
private ServiceProvider _serviceProvider; | ||
private ObjectFactory _factory; | ||
private object[] _factoryArguments; | ||
|
||
[GlobalSetup] | ||
public void SetUp() | ||
{ | ||
var collection = new ServiceCollection(); | ||
collection.AddTransient<TypeToBeActivated>(); | ||
collection.AddSingleton<DependencyA>(); | ||
collection.AddSingleton<DependencyB>(); | ||
collection.AddSingleton<DependencyC>(); | ||
collection.AddTransient<TypeToBeActivated>(); | ||
|
||
_serviceProvider = collection.BuildServiceProvider(); | ||
_factory = ActivatorUtilities.CreateFactory(typeof(TypeToBeActivated), new Type[] { typeof(DependencyB), typeof(DependencyC) }); | ||
_factoryArguments = new object[] { new DependencyB(), new DependencyC() }; | ||
} | ||
|
||
[Benchmark] | ||
public TypeToBeActivated ServiceProvider() => _serviceProvider.GetService<TypeToBeActivated>(); | ||
|
||
[Benchmark] | ||
public TypeToBeActivated Factory() => (TypeToBeActivated)_factory(_serviceProvider, _factoryArguments); | ||
|
||
[Benchmark] | ||
public TypeToBeActivated CreateInstance() => ActivatorUtilities.CreateInstance<TypeToBeActivated>(_serviceProvider, _factoryArguments); | ||
|
||
public class TypeToBeActivated | ||
{ | ||
public TypeToBeActivated(int i) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public TypeToBeActivated(string s) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public TypeToBeActivated(object o) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public TypeToBeActivated(DependencyA a, DependencyB b, DependencyC c) | ||
{ | ||
} | ||
} | ||
|
||
public class DependencyA {} | ||
public class DependencyB {} | ||
public class DependencyC {} | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
...enchmarks/micro/libraries/Microsoft.Extensions.DependencyInjection/GetServiceBenchmark.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using BenchmarkDotNet.Attributes; | ||
using MicroBenchmarks; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
[BenchmarkCategory(Categories.Libraries)] | ||
public class GetService : ServiceProviderEngineBenchmark | ||
{ | ||
private IServiceProvider _transientSp; | ||
private IServiceScope _scopedSp; | ||
private IServiceProvider _singletonSp; | ||
private IServiceProvider _serviceScopeFactoryProvider; | ||
private IServiceProvider _serviceScope; | ||
private IServiceProvider _emptyEnumerable; | ||
|
||
[Benchmark(Baseline = true)] | ||
public A NoDI() => new A(new B(new C())); | ||
|
||
[GlobalSetup(Target = nameof(Transient))] | ||
public void SetupTransient() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddTransient<A>(); | ||
services.AddTransient<B>(); | ||
services.AddTransient<C>(); | ||
_transientSp = services.BuildServiceProvider(new ServiceProviderOptions() | ||
{ | ||
#if INTERNAL_DI | ||
Mode = ServiceProviderMode | ||
#endif | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public A Transient() => _transientSp.GetService<A>(); | ||
|
||
[GlobalSetup(Target = nameof(Scoped))] | ||
public void SetupScoped() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddScoped<A>(); | ||
services.AddScoped<B>(); | ||
services.AddScoped<C>(); | ||
_scopedSp = services.BuildServiceProvider(new ServiceProviderOptions() | ||
{ | ||
#if INTERNAL_DI | ||
Mode = ServiceProviderMode | ||
#endif | ||
}).CreateScope(); | ||
} | ||
|
||
[Benchmark] | ||
public A Scoped() => _scopedSp.ServiceProvider.GetService<A>(); | ||
|
||
[GlobalSetup(Target = nameof(Singleton))] | ||
public void SetupScopedSingleton() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddSingleton<A>(); | ||
services.AddSingleton<B>(); | ||
services.AddSingleton<C>(); | ||
_singletonSp = services.BuildServiceProvider(new ServiceProviderOptions() | ||
{ | ||
#if INTERNAL_DI | ||
Mode = ServiceProviderMode | ||
#endif | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public A Singleton() => _singletonSp.GetService<A>(); | ||
|
||
[GlobalSetup(Target = nameof(ServiceScope))] | ||
public void ServiceScopeSetup() | ||
{ | ||
_serviceScope = new ServiceCollection().BuildServiceProvider(new ServiceProviderOptions() | ||
{ | ||
#if INTERNAL_DI | ||
Mode = ServiceProviderMode | ||
#endif | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public IServiceScope ServiceScope() => _serviceScope.CreateScope(); | ||
|
||
[GlobalSetup(Target = nameof(ServiceScopeProvider))] | ||
public void ServiceScopeProviderSetup() | ||
{ | ||
_serviceScopeFactoryProvider = new ServiceCollection().BuildServiceProvider(new ServiceProviderOptions() | ||
{ | ||
#if INTERNAL_DI | ||
Mode = ServiceProviderMode | ||
#endif | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public IServiceScopeFactory ServiceScopeProvider() => _serviceScopeFactoryProvider.GetService<IServiceScopeFactory>(); | ||
|
||
[GlobalSetup(Target = nameof(EmptyEnumerable))] | ||
public void EmptyEnumerableSetup() | ||
{ | ||
_emptyEnumerable = new ServiceCollection().BuildServiceProvider(new ServiceProviderOptions() | ||
{ | ||
#if INTERNAL_DI | ||
Mode = ServiceProviderMode | ||
#endif | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public object EmptyEnumerable() =>_emptyEnumerable.GetService<IEnumerable<A>>(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...icro/libraries/Microsoft.Extensions.DependencyInjection/IEnumerableGetServiceBenchmark.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using BenchmarkDotNet.Attributes; | ||
using MicroBenchmarks; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
[BenchmarkCategory(Categories.Libraries)] | ||
public class GetServiceIEnumerable : ServiceProviderEngineBenchmark | ||
{ | ||
private IServiceProvider _serviceProvider; | ||
|
||
[GlobalSetup(Target = nameof(Transient))] | ||
public void SetupTransient() => Setup(ServiceLifetime.Transient); | ||
|
||
[GlobalSetup(Target = nameof(Scoped))] | ||
public void SetupScoped() => Setup(ServiceLifetime.Scoped); | ||
|
||
[GlobalSetup(Target = nameof(Singleton))] | ||
public void SetupSingleton() => Setup(ServiceLifetime.Singleton); | ||
|
||
private void Setup(ServiceLifetime lifetime) | ||
{ | ||
IServiceCollection services = new ServiceCollection(); | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
services.Add(ServiceDescriptor.Describe(typeof(A), typeof(A), lifetime)); | ||
} | ||
|
||
services.Add(ServiceDescriptor.Describe(typeof(B), typeof(B), lifetime)); | ||
services.Add(ServiceDescriptor.Describe(typeof(C), typeof(C), lifetime)); | ||
|
||
_serviceProvider = services.BuildServiceProvider(new ServiceProviderOptions() | ||
{ | ||
#if INTERNAL_DI | ||
Mode = ServiceProviderMode | ||
#endif | ||
}).CreateScope().ServiceProvider; | ||
} | ||
|
||
[Benchmark] | ||
public object Transient() => _serviceProvider.GetService<IEnumerable<A>>(); | ||
|
||
[Benchmark] | ||
public object Scoped() => _serviceProvider.GetService<IEnumerable<A>>(); | ||
|
||
[Benchmark] | ||
public object Singleton() => _serviceProvider.GetService<IEnumerable<A>>(); | ||
} | ||
maryamariyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
51 changes: 51 additions & 0 deletions
51
...arks/micro/libraries/Microsoft.Extensions.DependencyInjection/ScopeValidationBenchmark.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using BenchmarkDotNet.Attributes; | ||
using MicroBenchmarks; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
[BenchmarkCategory(Categories.Libraries)] | ||
public class ScopeValidation | ||
{ | ||
private IServiceProvider _transientSp; | ||
private IServiceProvider _transientSpScopeValidation; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddTransient<A>(); | ||
services.AddTransient<B>(); | ||
services.AddTransient<C>(); | ||
_transientSp = services.BuildServiceProvider(); | ||
|
||
services = new ServiceCollection(); | ||
services.AddTransient<A>(); | ||
services.AddTransient<B>(); | ||
services.AddTransient<C>(); | ||
_transientSpScopeValidation = services.BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true }); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public A Transient() => _transientSp.GetService<A>(); | ||
|
||
[Benchmark] | ||
public A TransientWithScopeValidation() => _transientSpScopeValidation.GetService<A>(); | ||
|
||
public class A | ||
{ | ||
public A(B b) { } | ||
} | ||
|
||
public class B | ||
{ | ||
public B(C c) { } | ||
} | ||
public class C { } | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...icro/libraries/Microsoft.Extensions.DependencyInjection/ServiceProviderEngineBenchmark.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using BenchmarkDotNet.Attributes; | ||
using MicroBenchmarks; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
[BenchmarkCategory(Categories.Libraries)] | ||
public class ServiceProviderEngineBenchmark | ||
{ | ||
#if INTERNAL_DI | ||
maryamariyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
internal ServiceProviderMode ServiceProviderMode { get; private set; } | ||
|
||
[Params("Expressions", "Dynamic", "Runtime", "ILEmit")] | ||
public string Mode { | ||
set { | ||
ServiceProviderMode = (ServiceProviderMode)Enum.Parse(typeof(ServiceProviderMode), value); | ||
} | ||
} | ||
#endif | ||
|
||
public class A | ||
{ | ||
public A(B b) { } | ||
} | ||
|
||
public class B | ||
{ | ||
public B(C c) { } | ||
} | ||
|
||
public class C { } | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it would be great to remove
Benchmark
from the name but I don;t have any good ideas (ActivatorUtilitoes
would confilict with the type of the same name..)