|
1 | 1 | using System; |
| 2 | +using System.Threading.Tasks; |
2 | 3 | using BenchmarkDotNet.Attributes; |
3 | 4 | using BenchmarkDotNet.Jobs; |
4 | 5 | using DotNetCoreRpc.Client; |
|
8 | 9 |
|
9 | 10 | namespace Test.Client |
10 | 11 | { |
11 | | - [SimpleJob(RuntimeMoniker.NetCoreApp31)] |
| 12 | + [SimpleJob(RuntimeMoniker.Net70)] |
12 | 13 | [MemoryDiagnoser] |
13 | | - [RPlotExporter] |
14 | 14 | public class RpcClientBenchTest |
15 | 15 | { |
16 | 16 | private readonly IServiceCollection services; |
17 | 17 | private readonly IServiceProvider serviceProvider; |
18 | | - private readonly RpcClient rpcClient; |
19 | 18 | private readonly IPersonService personService; |
20 | 19 |
|
21 | | - [Params(1000)] |
22 | | - public int maxCount; |
23 | | - |
24 | 20 | public RpcClientBenchTest() |
25 | 21 | { |
26 | 22 | services = new ServiceCollection(); |
27 | | - services.AddDotNetCoreRpcClient() |
28 | | - .AddHttpClient("TestServer", client => { client.BaseAddress = new Uri("http://localhost:34047/"); }); |
| 23 | + services.AddHttpClient("TestServer", client => { client.BaseAddress = new Uri("http://localhost:34047/Test.Server6"); }) |
| 24 | + .AddDotNetCoreRpcClient(options => |
| 25 | + { |
| 26 | + options.AddRpcClient<IPersonService>().AddRpcClient<IProductService>(); |
| 27 | + }); |
29 | 28 |
|
30 | 29 | serviceProvider=services.BuildServiceProvider(); |
31 | | - rpcClient = serviceProvider.GetRequiredService<RpcClient>(); |
32 | | - rpcClient.CreateClient<IPersonService>("TestServer"); |
| 30 | + personService = serviceProvider.GetService<IPersonService>(); |
| 31 | + |
| 32 | + PersonModel person = new PersonModel |
| 33 | + { |
| 34 | + Id = 1, |
| 35 | + IdCardNo = 5555555, |
| 36 | + BirthDay = DateTime.Now, |
| 37 | + HasMoney = false |
| 38 | + }; |
| 39 | + person.Name = "softlgl" + person.Id; |
| 40 | + personService.Add(person).GetAwaiter().GetResult(); |
33 | 41 | } |
34 | 42 |
|
35 | 43 | [Benchmark] |
36 | 44 | public void GetTest() |
37 | 45 | { |
38 | | - for (int i = 0; i < maxCount; i++) |
39 | | - { |
40 | | - personService.Get(++i); |
41 | | - } |
| 46 | + personService.Get(1); |
42 | 47 | } |
43 | 48 |
|
| 49 | + |
44 | 50 | [Benchmark] |
45 | | - public async void AddTest() |
| 51 | + public async Task GetListTest() |
46 | 52 | { |
47 | | - for (int i = 0; i < maxCount; i++) |
48 | | - { |
49 | | - PersonModel person = new PersonModel |
50 | | - { |
51 | | - Id = ++i, |
52 | | - IdCardNo = 5555555, |
53 | | - BirthDay = DateTime.Now, |
54 | | - HasMoney = false |
55 | | - }; |
56 | | - person.Name = "softlgl" + person.Id; |
57 | | - bool add = await personService.Add(person); |
58 | | - } |
| 53 | + await personService.GetPersons(); |
59 | 54 | } |
| 55 | + |
| 56 | + //[Benchmark] |
| 57 | + //public async void AddTest() |
| 58 | + //{ |
| 59 | + // for (int i = 0; i < maxCount; i++) |
| 60 | + // { |
| 61 | + // PersonModel person = new PersonModel |
| 62 | + // { |
| 63 | + // Id = ++i, |
| 64 | + // IdCardNo = 5555555, |
| 65 | + // BirthDay = DateTime.Now, |
| 66 | + // HasMoney = false |
| 67 | + // }; |
| 68 | + // person.Name = "softlgl" + person.Id; |
| 69 | + // bool add = await personService.Add(person); |
| 70 | + // } |
| 71 | + //} |
60 | 72 | } |
61 | 73 | } |
0 commit comments