Skip to content

Commit 7799cf5

Browse files
committed
更新benchmark
1 parent 896b26b commit 7799cf5

6 files changed

+24
-20
lines changed

WebApiClientCore.Benchmarks/Requests/Benchmark.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ public void Setup()
3434
services
3535
.AddRefitClient<IRefitApi>(new RefitSettings
3636
{
37-
Buffered = true,
3837
})
3938
.AddHttpMessageHandler(() => new MockResponseHandler())
4039
.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://webapiclient.com/"));
4140

4241
this.ServiceProvider = services.BuildServiceProvider();
42+
this.ServiceProvider.GetService<IWebApiClientCoreApi>();
43+
this.ServiceProvider.GetService<IRefitApi>();
4344
}
4445
}
4546
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
```
22
3-
BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.4412/22H2/2022Update)
4-
Intel Core i3-4150 CPU 3.50GHz (Haswell), 1 CPU, 4 logical and 2 physical cores
3+
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3593/23H2/2023Update/SunValley3)
4+
Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
55
[Host] : .NET 8.0.4, X64 NativeAOT AVX2
66
77
Job=InProcess Toolchain=InProcessEmitToolchain
88
99
```
1010
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
1111
|-------------------------- |----------:|----------:|----------:|------:|--------:|-------:|----------:|------------:|
12-
| HttpClient_GetAsync | 2.203 μs | 0.0430 μs | 0.0574 μs | 0.42 | 0.01 | 1.3237 | 2.03 KB | 0.51 |
13-
| WebApiClientCore_GetAsync | 5.245 μs | 0.1027 μs | 0.1142 μs | 1.00 | 0.00 | 2.6169 | 4.02 KB | 1.00 |
14-
| Refit_GetAsync | 12.336 μs | 0.2447 μs | 0.6615 μs | 2.37 | 0.13 | 3.4790 | 5.34 KB | 1.33 |
12+
| HttpClient_GetAsync | 3.059 μs | 0.1315 μs | 0.3816 μs | 0.49 | 0.09 | 0.4959 | 2.03 KB | 0.51 |
13+
| WebApiClientCore_GetAsync | 6.277 μs | 0.2695 μs | 0.7903 μs | 1.00 | 0.00 | 0.9766 | 4.02 KB | 1.00 |
14+
| Refit_GetAsync | 14.295 μs | 0.4401 μs | 1.2626 μs | 2.30 | 0.31 | 1.2817 | 5.34 KB | 1.33 |
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
```
22
3-
BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.4412/22H2/2022Update)
4-
Intel Core i3-4150 CPU 3.50GHz (Haswell), 1 CPU, 4 logical and 2 physical cores
3+
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3593/23H2/2023Update/SunValley3)
4+
Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
55
[Host] : .NET 8.0.4, X64 NativeAOT AVX2
66
77
Job=InProcess Toolchain=InProcessEmitToolchain
88
99
```
1010
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
1111
|------------------------------- |----------:|----------:|----------:|------:|--------:|-------:|----------:|------------:|
12-
| HttpClient_PostJsonAsync | 2.760 μs | 0.0294 μs | 0.0246 μs | 0.48 | 0.01 | 1.5068 | 2.31 KB | 0.55 |
13-
| WebApiClientCore_PostJsonAsync | 5.712 μs | 0.0614 μs | 0.0512 μs | 1.00 | 0.00 | 2.7237 | 4.17 KB | 1.00 |
14-
| Refit_PostJsonAsync | 13.246 μs | 0.0457 μs | 0.0382 μs | 2.32 | 0.02 | 3.9215 | 6.02 KB | 1.44 |
12+
| HttpClient_PostJsonAsync | 3.804 μs | 0.1678 μs | 0.4813 μs | 0.60 | 0.11 | 0.5646 | 2.31 KB | 0.55 |
13+
| WebApiClientCore_PostJsonAsync | 6.528 μs | 0.2695 μs | 0.7945 μs | 1.00 | 0.00 | 1.0147 | 4.17 KB | 1.00 |
14+
| Refit_PostJsonAsync | 13.823 μs | 0.5368 μs | 1.5658 μs | 2.16 | 0.38 | 1.4038 | 5.83 KB | 1.40 |
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
```
22
3-
BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.4412/22H2/2022Update)
4-
Intel Core i3-4150 CPU 3.50GHz (Haswell), 1 CPU, 4 logical and 2 physical cores
3+
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3593/23H2/2023Update/SunValley3)
4+
Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
55
[Host] : .NET 8.0.4, X64 NativeAOT AVX2
66
77
Job=InProcess Toolchain=InProcessEmitToolchain
88
99
```
10-
| Method | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
11-
|------------------------------ |----------:|----------:|----------:|----------:|------:|--------:|-------:|----------:|------------:|
12-
| WebApiClientCore_PutFormAsync | 8.689 μs | 0.1715 μs | 0.3136 μs | 8.733 μs | 1.00 | 0.00 | 3.2501 | 5 KB | 1.00 |
13-
| Refit_PutFormAsync | 20.598 μs | 0.4215 μs | 1.2429 μs | 21.112 μs | 2.37 | 0.17 | 4.5776 | 7.05 KB | 1.41 |
10+
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
11+
|------------------------------ |---------:|---------:|---------:|------:|--------:|-------:|----------:|------------:|
12+
| WebApiClientCore_PutFormAsync | 10.45 μs | 0.415 μs | 1.204 μs | 1.00 | 0.00 | 1.2207 | 5 KB | 1.00 |
13+
| Refit_PutFormAsync | 22.70 μs | 1.261 μs | 3.717 μs | 2.19 | 0.33 | 1.6785 | 6.89 KB | 1.38 |

WebApiClientCore/Implementations/SourceGeneratorHttpApiActivator.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.Linq;
55
using System.Reflection;
6+
using System.Runtime.CompilerServices;
67
using WebApiClientCore.Exceptions;
78
using WebApiClientCore.Internals;
89

@@ -21,7 +22,7 @@ public class SourceGeneratorHttpApiActivator<
2122
{
2223
private readonly ApiActionInvoker[] actionInvokers;
2324
private readonly Func<IHttpApiInterceptor, ApiActionInvoker[], THttpApi> activator;
24-
private static readonly Type? _proxyClassType = SourceGeneratorProxyClassType.Find(typeof(THttpApi));
25+
private static readonly Type? _proxyClassType = SourceGeneratorProxyClassFinder.Find(typeof(THttpApi));
2526

2627
/// <summary>
2728
/// 获取是否支持
@@ -51,7 +52,9 @@ public SourceGeneratorHttpApiActivator(IApiActionDescriptorProvider apiActionDes
5152
.Select(actionInvokerProvider.CreateActionInvoker)
5253
.ToArray();
5354

54-
this.activator = LambdaUtil.CreateCtorFunc<IHttpApiInterceptor, ApiActionInvoker[], THttpApi>(proxyClassType);
55+
this.activator = RuntimeFeature.IsDynamicCodeSupported
56+
? LambdaUtil.CreateCtorFunc<IHttpApiInterceptor, ApiActionInvoker[], THttpApi>(proxyClassType)
57+
: (interceptor, invokers) => proxyClassType.CreateInstance<THttpApi>(interceptor, invokers);
5558
}
5659

5760
/// <summary>

WebApiClientCore/Implementations/SourceGeneratorProxyClassType.cs renamed to WebApiClientCore/Implementations/SourceGeneratorProxyClassFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace WebApiClientCore.Implementations
77
/// <summary>
88
/// 提供获取SourceGenerator生成的代理类型
99
/// </summary>
10-
static class SourceGeneratorProxyClassType
10+
static class SourceGeneratorProxyClassFinder
1111
{
1212
private static readonly object syncRoot = new();
1313
private static readonly HashSet<Assembly> assemblies = [];

0 commit comments

Comments
 (0)