Skip to content

Commit

Permalink
更新benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Jun 7, 2024
1 parent 896b26b commit 7799cf5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
3 changes: 2 additions & 1 deletion WebApiClientCore.Benchmarks/Requests/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ public void Setup()
services
.AddRefitClient<IRefitApi>(new RefitSettings
{
Buffered = true,
})
.AddHttpMessageHandler(() => new MockResponseHandler())
.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://webapiclient.com/"));

this.ServiceProvider = services.BuildServiceProvider();
this.ServiceProvider.GetService<IWebApiClientCoreApi>();
this.ServiceProvider.GetService<IRefitApi>();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
```
BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.4412/22H2/2022Update)
Intel Core i3-4150 CPU 3.50GHz (Haswell), 1 CPU, 4 logical and 2 physical cores
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3593/23H2/2023Update/SunValley3)
Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
[Host] : .NET 8.0.4, X64 NativeAOT AVX2
Job=InProcess Toolchain=InProcessEmitToolchain
```
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
|-------------------------- |----------:|----------:|----------:|------:|--------:|-------:|----------:|------------:|
| HttpClient_GetAsync | 2.203 μs | 0.0430 μs | 0.0574 μs | 0.42 | 0.01 | 1.3237 | 2.03 KB | 0.51 |
| WebApiClientCore_GetAsync | 5.245 μs | 0.1027 μs | 0.1142 μs | 1.00 | 0.00 | 2.6169 | 4.02 KB | 1.00 |
| Refit_GetAsync | 12.336 μs | 0.2447 μs | 0.6615 μs | 2.37 | 0.13 | 3.4790 | 5.34 KB | 1.33 |
| HttpClient_GetAsync | 3.059 μs | 0.1315 μs | 0.3816 μs | 0.49 | 0.09 | 0.4959 | 2.03 KB | 0.51 |
| WebApiClientCore_GetAsync | 6.277 μs | 0.2695 μs | 0.7903 μs | 1.00 | 0.00 | 0.9766 | 4.02 KB | 1.00 |
| 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 number Diff line number Diff line change
@@ -1,14 +1,14 @@
```
BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.4412/22H2/2022Update)
Intel Core i3-4150 CPU 3.50GHz (Haswell), 1 CPU, 4 logical and 2 physical cores
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3593/23H2/2023Update/SunValley3)
Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
[Host] : .NET 8.0.4, X64 NativeAOT AVX2
Job=InProcess Toolchain=InProcessEmitToolchain
```
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
|------------------------------- |----------:|----------:|----------:|------:|--------:|-------:|----------:|------------:|
| HttpClient_PostJsonAsync | 2.760 μs | 0.0294 μs | 0.0246 μs | 0.48 | 0.01 | 1.5068 | 2.31 KB | 0.55 |
| WebApiClientCore_PostJsonAsync | 5.712 μs | 0.0614 μs | 0.0512 μs | 1.00 | 0.00 | 2.7237 | 4.17 KB | 1.00 |
| Refit_PostJsonAsync | 13.246 μs | 0.0457 μs | 0.0382 μs | 2.32 | 0.02 | 3.9215 | 6.02 KB | 1.44 |
| HttpClient_PostJsonAsync | 3.804 μs | 0.1678 μs | 0.4813 μs | 0.60 | 0.11 | 0.5646 | 2.31 KB | 0.55 |
| WebApiClientCore_PostJsonAsync | 6.528 μs | 0.2695 μs | 0.7945 μs | 1.00 | 0.00 | 1.0147 | 4.17 KB | 1.00 |
| 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 number Diff line number Diff line change
@@ -1,13 +1,13 @@
```
BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.4412/22H2/2022Update)
Intel Core i3-4150 CPU 3.50GHz (Haswell), 1 CPU, 4 logical and 2 physical cores
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3593/23H2/2023Update/SunValley3)
Intel Core i7-8565U CPU 1.80GHz (Whiskey Lake), 1 CPU, 8 logical and 4 physical cores
[Host] : .NET 8.0.4, X64 NativeAOT AVX2
Job=InProcess Toolchain=InProcessEmitToolchain
```
| Method | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
|------------------------------ |----------:|----------:|----------:|----------:|------:|--------:|-------:|----------:|------------:|
| WebApiClientCore_PutFormAsync | 8.689 μs | 0.1715 μs | 0.3136 μs | 8.733 μs | 1.00 | 0.00 | 3.2501 | 5 KB | 1.00 |
| 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 |
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
|------------------------------ |---------:|---------:|---------:|------:|--------:|-------:|----------:|------------:|
| WebApiClientCore_PutFormAsync | 10.45 μs | 0.415 μs | 1.204 μs | 1.00 | 0.00 | 1.2207 | 5 KB | 1.00 |
| Refit_PutFormAsync | 22.70 μs | 1.261 μs | 3.717 μs | 2.19 | 0.33 | 1.6785 | 6.89 KB | 1.38 |
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using WebApiClientCore.Exceptions;
using WebApiClientCore.Internals;

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

/// <summary>
/// 获取是否支持
Expand Down Expand Up @@ -51,7 +52,9 @@ public SourceGeneratorHttpApiActivator(IApiActionDescriptorProvider apiActionDes
.Select(actionInvokerProvider.CreateActionInvoker)
.ToArray();

this.activator = LambdaUtil.CreateCtorFunc<IHttpApiInterceptor, ApiActionInvoker[], THttpApi>(proxyClassType);
this.activator = RuntimeFeature.IsDynamicCodeSupported
? LambdaUtil.CreateCtorFunc<IHttpApiInterceptor, ApiActionInvoker[], THttpApi>(proxyClassType)
: (interceptor, invokers) => proxyClassType.CreateInstance<THttpApi>(interceptor, invokers);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace WebApiClientCore.Implementations
/// <summary>
/// 提供获取SourceGenerator生成的代理类型
/// </summary>
static class SourceGeneratorProxyClassType
static class SourceGeneratorProxyClassFinder
{
private static readonly object syncRoot = new();
private static readonly HashSet<Assembly> assemblies = [];
Expand Down

0 comments on commit 7799cf5

Please sign in to comment.