Skip to content

Commit

Permalink
Add RateLimit benchmarks (#910)
Browse files Browse the repository at this point in the history
* Add RateLimit benchmarks

Add benchmarks for the rate-limit policy.

* Change NuGet baseline

The latest release is 7.2.3, not 7.3.0.
  • Loading branch information
martincostello authored Jan 17, 2022
1 parent dfa9040 commit ac01478
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Polly.Benchmarks/PollyConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private static Job PollyJob(Job job, bool useNuGet)

if (useNuGet)
{
result = result.WithNuGet("Polly", "7.2.1");
result = result.WithNuGet("Polly", "7.2.3");
}

return result;
Expand Down
37 changes: 37 additions & 0 deletions src/Polly.Benchmarks/RateLimit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;

namespace Polly.Benchmarks
{
[Config(typeof(PollyConfig))]
public class RateLimit
{
private static readonly Policy SyncPolicy = Policy.RateLimit(20, TimeSpan.FromSeconds(1), int.MaxValue);
private static readonly AsyncPolicy AsyncPolicy = Policy.RateLimitAsync(20, TimeSpan.FromSeconds(1), int.MaxValue);

[Benchmark]
public void RateLimit_Synchronous_Succeeds()
{
SyncPolicy.Execute(() => Workloads.Action());
}

[Benchmark]
public async Task RateLimit_Asynchronous_Succeeds()
{
await AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync());
}

[Benchmark]
public int RateLimit_Synchronous_With_Result_Succeeds()
{
return SyncPolicy.Execute(() => Workloads.Func<int>());
}

[Benchmark]
public async Task<int> RateLimit_Asynchronous_With_Result_Succeeds()
{
return await AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync<int>());
}
}
}

0 comments on commit ac01478

Please sign in to comment.