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.
 
 
 
 

48 rivejä
1.4 KiB

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