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.
 
 
 
 

53 line
1.3 KiB

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