選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

49 行
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. [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. }