-
Notifications
You must be signed in to change notification settings - Fork 449
Expand file tree
/
Copy pathHttpPutFormBenchmark.cs
More file actions
41 lines (38 loc) · 1.64 KB
/
HttpPutFormBenchmark.cs
File metadata and controls
41 lines (38 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using BenchmarkDotNet.Attributes;
using Microsoft.Extensions.DependencyInjection;
using RestSharp;
using System.Threading.Tasks;
namespace WebApiClientCore.Benchmarks.Requests
{
public class HttpPutFormBenchmark : Benchmark
{
[Benchmark(Baseline = true)]
public async Task<User> WebApiClientCore_PutFormAsync()
{
using var scope = this.ServiceProvider.CreateScope();
var benchmarkApi = scope.ServiceProvider.GetRequiredService<IWebApiClientCoreJsonApi>();
return await benchmarkApi.PutFormAsync(id: "id001", User.Instance);
}
[Benchmark]
public async Task<User> Refit_PutFormAsync()
{
using var scope = this.ServiceProvider.CreateScope();
var benchmarkApi = scope.ServiceProvider.GetRequiredService<IRefitJsonApi>();
return await benchmarkApi.PutFormAsync(id: "id001", User.Instance);
}
[Benchmark]
public async Task<User> RestSharp_PutFormAsync()
{
using var scope = this.ServiceProvider.CreateScope();
var client = scope.ServiceProvider.GetRequiredService<RestSharpJsonClient>();
var request = new RestRequest($"/benchmarks/id001")
.AddParameter("id", User.Instance.Id)
.AddParameter("name", User.Instance.Name)
.AddParameter("bio", User.Instance.Bio)
.AddParameter("followers", User.Instance.Followers)
.AddParameter("following", User.Instance.Following)
.AddParameter("url", User.Instance.Url);
return await client.PutAsync<User>(request);
}
}
}