Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

MessageProcessingBenchmark.cs 1.3 KiB

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