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.
 
 
 
 

54 lines
1.4 KiB

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