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.
 
 
 
 

55 rivejä
1.4 KiB

  1. using BenchmarkDotNet.Attributes;
  2. using BenchmarkDotNet.Attributes.Exporters;
  3. using BenchmarkDotNet.Attributes.Jobs;
  4. using MQTTnet.Diagnostics;
  5. namespace MQTTnet.Benchmarks
  6. {
  7. [ClrJob]
  8. [RPlotExporter]
  9. [MemoryDiagnoser]
  10. public class LoggerBenchmark
  11. {
  12. private IMqttNetLogger _logger;
  13. private IMqttNetChildLogger _childLogger;
  14. private bool _useHandler;
  15. [GlobalSetup]
  16. public void Setup()
  17. {
  18. _logger = new MqttNetLogger("1");
  19. _childLogger = _logger.CreateChildLogger("child");
  20. MqttNetGlobalLogger.LogMessagePublished += OnLogMessagePublished;
  21. }
  22. private void OnLogMessagePublished(object sender, MqttNetLogMessagePublishedEventArgs eventArgs)
  23. {
  24. if (_useHandler)
  25. {
  26. eventArgs.TraceMessage.ToString();
  27. }
  28. }
  29. [Benchmark]
  30. public void Log_10000_Messages_NoHandler()
  31. {
  32. _useHandler = false;
  33. for (var i = 0; i < 10000; i++)
  34. {
  35. _childLogger.Verbose("test log message {0}", "parameter");
  36. }
  37. }
  38. [Benchmark]
  39. public void Log_10000_Messages_WithHandler()
  40. {
  41. _useHandler = true;
  42. for (var i = 0; i < 10000; i++)
  43. {
  44. _childLogger.Verbose("test log message {0}", "parameter");
  45. }
  46. }
  47. }
  48. }