Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

MessageProcessingBenchmark.cs 1.4 KiB

pirms 6 gadiem
pirms 6 gadiem
pirms 6 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using BenchmarkDotNet.Attributes;
  2. using BenchmarkDotNet.Attributes.Columns;
  3. using BenchmarkDotNet.Attributes.Exporters;
  4. using BenchmarkDotNet.Attributes.Jobs;
  5. using MQTTnet.Client;
  6. using MQTTnet.Server;
  7. namespace MQTTnet.Benchmarks
  8. {
  9. [ClrJob]
  10. [RPlotExporter, RankColumn]
  11. [MemoryDiagnoser]
  12. public class MessageProcessingBenchmark
  13. {
  14. private IMqttServer _mqttServer;
  15. private IMqttClient _mqttClient;
  16. private MqttApplicationMessage _message;
  17. [GlobalSetup]
  18. public void Setup()
  19. {
  20. var factory = new MqttFactory();
  21. _mqttServer = factory.CreateMqttServer();
  22. _mqttClient = factory.CreateMqttClient();
  23. var serverOptions = new MqttServerOptionsBuilder().Build();
  24. _mqttServer.StartAsync(serverOptions).GetAwaiter().GetResult();
  25. var clientOptions = new MqttClientOptionsBuilder()
  26. .WithTcpServer("localhost").Build();
  27. _mqttClient.ConnectAsync(clientOptions).GetAwaiter().GetResult();
  28. _message = new MqttApplicationMessageBuilder()
  29. .WithTopic("A")
  30. .Build();
  31. }
  32. [Benchmark]
  33. public void Send_10000_Messages()
  34. {
  35. for (var i = 0; i < 10000; i++)
  36. {
  37. _mqttClient.PublishAsync(_message).GetAwaiter().GetResult();
  38. }
  39. }
  40. }
  41. }