Skip to content

Commit

Permalink
Add ResilienceStrategyProviderBenchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk committed May 25, 2023
1 parent e5f2f62 commit 3d804c4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
``` ini

BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.22621.1702/22H2/2022Update/SunValley2), VM=Hyper-V
Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
.NET SDK=7.0.302
[Host] : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2

Job=MediumRun Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=2 WarmupCount=10

```
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|--------------- |---------:|---------:|---------:|-------:|----------:|
| Get_Ok | 25.31 ns | 0.463 ns | 0.663 ns | 0.0013 | 32 B |
| Get_Generic_Ok | 58.16 ns | 0.669 ns | 1.001 ns | 0.0013 | 32 B |
4 changes: 3 additions & 1 deletion src/Polly.Core.Benchmarks/Polly.Core.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
</PropertyGroup>

<ItemGroup>
<Using Include="Polly.Core.Benchmarks.Utils"/>
<Using Include="Polly.Core.Benchmarks.Utils" />
<ProjectReference Include="..\Polly.Core\Polly.Core.csproj" />
<ProjectReference Include="..\Polly.Extensions\Polly.Extensions.csproj" />
<ProjectReference Include="..\Polly.RateLimiting\Polly.RateLimiting.csproj" />
<ProjectReference Include="..\Polly\Polly.csproj" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions src/Polly.Core.Benchmarks/ResilienceStrategyProviderBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using BenchmarkDotNet.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Polly.Core.Benchmarks;

namespace Polly.Core.Benchmarks;

public class ResilienceStrategyProviderBenchmark
{
private ResilienceStrategyProvider<string>? _provider;

[GlobalSetup]
public void Setup()
{
_provider = new ServiceCollection()
.AddResilienceStrategy("dummy", builder => builder.AddTimeout(new TimeoutStrategyOptions()))
.AddResilienceStrategy<string, string>("dummy", builder => builder.AddTimeout(new TimeoutStrategyOptions()))
.BuildServiceProvider()
.GetRequiredService<ResilienceStrategyProvider<string>>();
}

[Benchmark]
public void Get_Ok() => _provider!.Get("dummy");

[Benchmark]
public void Get_Generic_Ok() => _provider!.Get<string>("dummy");
}

0 comments on commit 3d804c4

Please sign in to comment.