You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.6 KiB

  1. using BenchmarkDotNet.Attributes;
  2. using BenchmarkDotNet.Configs;
  3. using BenchmarkDotNet.Environments;
  4. using BenchmarkDotNet.Jobs;
  5. using BenchmarkDotNet.Toolchains.CsProj;
  6. using JT809.Protocol.JT809Enums;
  7. using JT809.Protocol.JT809MessageBody;
  8. using JT809.Protocol.JT809SubMessageBody;
  9. using JT809.Protocol.JT809Extensions;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. namespace JT809.Protocol.Benchmark
  14. {
  15. [Config(typeof(JT809SerializerContextConfig))]
  16. [MarkdownExporter]
  17. [MemoryDiagnoser]
  18. public class JT809SerializerContext
  19. {
  20. private byte[] bytes;
  21. [Params(100, 10000,100000)]
  22. public int N;
  23. [GlobalSetup]
  24. public void Setup()
  25. {
  26. bytes = "5B 00 00 00 92 00 00 06 82 94 00 01 33 EF B8 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 94 01 00 00 00 5C 01 00 02 00 00 00 00 5A 01 AC 3F 40 12 3F FA A1 00 00 00 00 5A 01 AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BA D8 5D".ToHexBytes();
  27. }
  28. [Benchmark(Description = "JT809_0x9400_0x9401_Package_Deserialize")]
  29. public void JT809_0x9400_0x9401_Package_Deserialize_Test()
  30. {
  31. for (int i = 0; i < N; i++)
  32. {
  33. var result = JT809Serializer.Deserialize(bytes);
  34. }
  35. }
  36. [Benchmark(Description = "JT809_0x9400_0x9401_Package_Serialize")]
  37. public void JT809_0x9400_0x9401_Package_Serialize_Test()
  38. {
  39. for (int i = 0; i < N; i++)
  40. {
  41. JT809Package jT809Package = new JT809Package();
  42. jT809Package.Header = new JT809Header
  43. {
  44. MsgSN = 1666,
  45. EncryptKey = 9999,
  46. EncryptFlag = JT809Header_Encrypt.None,
  47. Version = new JT809Header_Version(1, 0, 0),
  48. BusinessType = JT809Enums.JT809BusinessType.从链路报警信息交互消息,
  49. MsgGNSSCENTERID = 20180920,
  50. };
  51. JT809_0x9400 bodies = new JT809_0x9400
  52. {
  53. VehicleNo = "粤A12345",
  54. VehicleColor = JT809Enums.JT809VehicleColorType.黄色,
  55. SubBusinessType = JT809Enums.JT809SubBusinessType.报警督办请求,
  56. };
  57. JT809_0x9400_0x9401 jT809_0x9400_0x9401 = new JT809_0x9400_0x9401
  58. {
  59. WarnSrc = JT809WarnSrc.车载终端,
  60. WarnType = JT809WarnType.疲劳驾驶报警,
  61. WarnTime = DateTime.Parse("2018-09-27 10:24:00"),
  62. SupervisionID = "123FFAA1",
  63. SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"),
  64. SupervisionLevel = 3,
  65. Supervisor = "smallchi",
  66. SupervisorTel = "12345678901",
  67. SupervisorEmail = "123456@qq.com"
  68. };
  69. bodies.SubBodies = jT809_0x9400_0x9401;
  70. jT809Package.Bodies = bodies;
  71. var hex = JT809Serializer.Serialize(jT809Package);
  72. }
  73. }
  74. }
  75. public class JT809SerializerContextConfig : ManualConfig
  76. {
  77. public JT809SerializerContextConfig()
  78. {
  79. Add(Job.Default.WithGcServer(true).With(Runtime.Clr).With(Platform.AnyCpu));
  80. Add(Job.Default.WithGcServer(true).With(CsProjCoreToolchain.NetCoreApp21).With(Platform.AnyCpu));
  81. }
  82. }
  83. }