Skip to content

Commit b5540a0

Browse files
committed
benchmark
1 parent 1ef1b49 commit b5540a0

7 files changed

+26
-31
lines changed

WebApiClientCore.Benchmarks/Requests/GetBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class GetBenchmark : Benchmark
1616
/// 使用原生HttpClient请求
1717
/// </summary>
1818
/// <returns></returns>
19-
[Benchmark(Baseline = true)]
19+
[Benchmark]
2020
public async Task<Model> HttpClient_GetAsync()
2121
{
2222
using var scope = this.ServiceProvider.CreateScope();
@@ -34,7 +34,7 @@ public async Task<Model> HttpClient_GetAsync()
3434
/// 使用WebApiClientCore请求
3535
/// </summary>
3636
/// <returns></returns>
37-
[Benchmark]
37+
[Benchmark(Baseline = true)]
3838
public async Task<Model> WebApiClientCore_GetAsync()
3939
{
4040
using var scope = this.ServiceProvider.CreateScope();

WebApiClientCore.Benchmarks/Requests/PostJsonBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class PostJsonBenchmark : Benchmark
1616
/// 使用原生HttpClient请求
1717
/// </summary>
1818
/// <returns></returns>
19-
[Benchmark(Baseline = true)]
19+
[Benchmark]
2020
public async Task<Model> HttpClient_PostJsonAsync()
2121
{
2222
using var scope = this.ServiceProvider.CreateScope();
@@ -38,7 +38,7 @@ public async Task<Model> HttpClient_PostJsonAsync()
3838
/// 使用WebApiClientCore请求
3939
/// </summary>
4040
/// <returns></returns>
41-
[Benchmark]
41+
[Benchmark(Baseline = true)]
4242
public async Task<Model> WebApiClientCore_PostJsonAsync()
4343
{
4444
using var scope = this.ServiceProvider.CreateScope();

WebApiClientCore.Benchmarks/WebApiClientCore.Benchmarks.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<OutputType>Exe</OutputType>
66
<SignAssembly>true</SignAssembly>
77
<AssemblyOriginatorKeyFile>Sign.snk</AssemblyOriginatorKeyFile>
@@ -18,10 +18,4 @@
1818
<ProjectReference Include="..\WebApiClientCore\WebApiClientCore.csproj" />
1919
</ItemGroup>
2020

21-
<ItemGroup>
22-
<None Update="..\icon.png">
23-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24-
</None>
25-
</ItemGroup>
26-
2721
</Project>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
```
22
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
5-
[Host] : .NET 6.0.29, X64 NativeAOT AVX2
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
5+
[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 | 3.201 μs | 0.0624 μs | 0.0811 μs | 1.00 | 0.00 | 0.5379 | 2.2 KB | 1.00 |
13-
| WebApiClientCore_GetAsync | 8.726 μs | 0.1179 μs | 0.1103 μs | 2.71 | 0.10 | 1.1139 | 4.59 KB | 2.08 |
14-
| Refit_GetAsync | 17.237 μs | 0.2066 μs | 0.1933 μs | 5.34 | 0.17 | 1.3733 | 5.67 KB | 2.57 |
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 |
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
```
22
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
5-
[Host] : .NET 6.0.29, X64 NativeAOT AVX2
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
5+
[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 | 4.372 μs | 0.0680 μs | 0.0568 μs | 1.00 | 0.00 | 0.6409 | 2.64 KB | 1.00 |
13-
| WebApiClientCore_PostJsonAsync | 10.299 μs | 0.1485 μs | 0.1389 μs | 2.35 | 0.04 | 1.1902 | 4.9 KB | 1.86 |
14-
| Refit_PostJsonAsync | 21.006 μs | 0.4003 μs | 0.7320 μs | 4.84 | 0.19 | 1.5869 | 6.53 KB | 2.47 |
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 |
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
```
22
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
5-
[Host] : .NET 6.0.29, X64 NativeAOT AVX2
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
5+
[Host] : .NET 8.0.4, X64 NativeAOT AVX2
66
77
Job=InProcess Toolchain=InProcessEmitToolchain
88
99
```
10-
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
11-
|------------------------------ |---------:|---------:|---------:|------:|--------:|-------:|----------:|------------:|
12-
| WebApiClientCore_PutFormAsync | 15.09 μs | 0.290 μs | 0.705 μs | 1.00 | 0.00 | 1.4038 | 5.77 KB | 1.00 |
13-
| Refit_PutFormAsync | 27.61 μs | 0.544 μs | 1.333 μs | 1.83 | 0.12 | 1.8311 | 7.54 KB | 1.31 |
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 |

WebApiClientCore/Implementations/SourceGeneratorHttpApiActivator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Reflection;
44
using WebApiClientCore.Exceptions;
5+
using WebApiClientCore.Internals;
56

67
namespace WebApiClientCore.Implementations
78
{
@@ -47,7 +48,7 @@ public SourceGeneratorHttpApiActivator(IApiActionDescriptorProvider apiActionDes
4748
.Select(actionInvokerProvider.CreateActionInvoker)
4849
.ToArray();
4950

50-
this.activator = (interceptor, invokers) => proxyType.CreateInstance<THttpApi>(interceptor, invokers);
51+
this.activator = LambdaUtil.CreateCtorFunc<IHttpApiInterceptor, ApiActionInvoker[], THttpApi>(proxyType);
5152
}
5253

5354
/// <summary>

0 commit comments

Comments
 (0)