Skip to content

Commit

Permalink
Add DelegatingComponent benchmark
Browse files Browse the repository at this point in the history
Add a micro-benchmark for `DelegatingComponent` code path for non-AoT and AoT.
  • Loading branch information
martincostello committed Oct 30, 2023
1 parent 68dbc79 commit b85d45c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```
BenchmarkDotNet v0.13.9+228a464e8be6c580ad9408e98f18813f6407fb5a, Windows 11 (10.0.22621.2428/22H2/2022Update/SunValley2)
12th Gen Intel Core i7-1270P, 1 CPU, 16 logical and 12 physical cores
.NET SDK 7.0.403
[Host] : .NET 7.0.13 (7.0.1323.51816), X64 RyuJIT AVX2
Job=MediumRun Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=2 WarmupCount=10
```
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
|------------------------------------ |---------:|---------:|---------:|------:|--------:|-------:|----------:|------------:|
| DelegatingComponent_ExecuteCore_Jit | 29.40 ns | 0.699 ns | 1.025 ns | 1.00 | 0.00 | - | - | NA |
| DelegatingComponent_ExecuteCore_Aot | 34.65 ns | 0.627 ns | 0.919 ns | 1.18 | 0.05 | 0.0025 | 24 B | NA |
38 changes: 38 additions & 0 deletions bench/Polly.Core.Benchmarks/DelegatingComponentBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Polly.Utils.Pipeline;

namespace Polly.Core.Benchmarks;

public class DelegatingComponentBenchmark : IAsyncDisposable
{
private ResilienceContext? _context;
private DelegatingComponent? _component;

[GlobalSetup]
public void Setup()
{
var first = PipelineComponent.Empty;
var second = PipelineComponent.Empty;

_component = new DelegatingComponent(first) { Next = second };
_context = ResilienceContextPool.Shared.Get();
}

public async ValueTask DisposeAsync()
{
if (_component is not null)
{
await _component.DisposeAsync().ConfigureAwait(false);
_component = null;
}

GC.SuppressFinalize(this);
}

[Benchmark(Baseline = true)]
public ValueTask<Outcome<int>> DelegatingComponent_ExecuteCore_Jit()
=> _component!.ExecuteComponent((_, state) => Outcome.FromResultAsValueTask(state), _context!, 42);

[Benchmark]
public ValueTask<Outcome<int>> DelegatingComponent_ExecuteCore_Aot()
=> _component!.ExecuteComponentAot((_, state) => Outcome.FromResultAsValueTask(state), _context!, 42);
}

0 comments on commit b85d45c

Please sign in to comment.