-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
dfa9040
commit ac01478
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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,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>()); | ||
} | ||
} | ||
} |