diff --git a/src/Polly.Benchmarks/PollyConfig.cs b/src/Polly.Benchmarks/PollyConfig.cs index d490ae4d09c..cad9e4148df 100644 --- a/src/Polly.Benchmarks/PollyConfig.cs +++ b/src/Polly.Benchmarks/PollyConfig.cs @@ -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; diff --git a/src/Polly.Benchmarks/RateLimit.cs b/src/Polly.Benchmarks/RateLimit.cs new file mode 100644 index 00000000000..e883a5e9ba5 --- /dev/null +++ b/src/Polly.Benchmarks/RateLimit.cs @@ -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()); + } + + [Benchmark] + public async Task RateLimit_Asynchronous_With_Result_Succeeds() + { + return await AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync()); + } + } +}