No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

48 líneas
1.3 KiB

  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. }