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.

MessageProcessingBenchmark.cs 1.3 KiB

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