| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System;
- using System.Threading.Tasks;
- namespace Model
- {
- [ObjectEvent]
- public class BenchmarkComponentEvent : ObjectEvent<BenchmarkComponent>, IAwake<string>
- {
- public void Awake(string address)
- {
- this.Get().Awake(address);
- }
- }
- public class BenchmarkComponent: Component
- {
- private int k;
- private long time1 = TimeHelper.ClientNow();
- public async void Awake(string address)
- {
- try
- {
- NetOuterComponent networkComponent = Game.Scene.GetComponent<NetOuterComponent>();
- for (int i = 0; i < 100; i++)
- {
- await Game.Scene.GetComponent<TimerComponent>().WaitAsync(1000);
- this.TestAsync(networkComponent, address, i);
- }
- }
- catch (Exception e)
- {
- Log.Error(e.ToString());
- }
- }
- public async void TestAsync(NetOuterComponent networkComponent, string address, int j)
- {
- try
- {
- using (Session session = networkComponent.Create(address))
- {
- int i = 0;
- while (i < 100000000)
- {
- ++i;
- await Game.Scene.GetComponent<TimerComponent>().WaitAsync(10);
- await this.Send(session, j);
- }
- }
- }
- catch (RpcException e)
- {
- Log.Error(e.ToString());
- }
- catch (Exception e)
- {
- Log.Error(e.ToString());
- }
- }
- public async Task Send(Session session, int j)
- {
- try
- {
- await session.Call<R2C_Ping>(new C2R_Ping());
- ++this.k;
- if (this.k % 10000 != 0)
- {
- return;
- }
- long time2 = TimeHelper.ClientNow();
- long time = time2 - this.time1;
- this.time1 = time2;
- Log.Info($"Benchmark k: {this.k} 每10W次耗时: {time} ms");
- }
- catch (Exception e)
- {
- Log.Error(e.ToString());
- }
- }
- public override void Dispose()
- {
- if (this.Id == 0)
- {
- return;
- }
- base.Dispose();
- }
- }
- }
|