BenchmarkComponent.cs 979 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using Base;
  3. namespace Model
  4. {
  5. public class BenchmarkComponent: Component
  6. {
  7. private int k;
  8. private long time1 = TimeHelper.ClientNow();
  9. public async void TestAsync(NetOuterComponent networkComponent, string address, int j)
  10. {
  11. try
  12. {
  13. using (Session session = networkComponent.Create(address))
  14. {
  15. int i = 0;
  16. while (i < 10000000)
  17. {
  18. ++i;
  19. await session.Call<C2R_Ping, R2C_Ping>(new C2R_Ping());
  20. ++this.k;
  21. if (this.k % 100000 != 0)
  22. {
  23. continue;
  24. }
  25. long time2 = TimeHelper.ClientNow();
  26. long time = time2 - this.time1;
  27. this.time1 = time2;
  28. Log.Info($"{j} Benchmark k: {this.k} 每10W次耗时: {time} ms");
  29. }
  30. }
  31. }
  32. catch (RpcException e)
  33. {
  34. Log.Error(e.ToString());
  35. }
  36. catch (Exception e)
  37. {
  38. Log.Error(e.ToString());
  39. }
  40. }
  41. public override void Dispose()
  42. {
  43. if (this.Id == 0)
  44. {
  45. return;
  46. }
  47. base.Dispose();
  48. }
  49. }
  50. }