No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

88 líneas
2.5 KiB

  1. using BenchmarkDotNet.Attributes;
  2. using BenchmarkDotNet.Jobs;
  3. using MQTTnet.Diagnostics.Logger;
  4. namespace MQTTnet.Benchmarks
  5. {
  6. [SimpleJob(RuntimeMoniker.Net461)]
  7. [RPlotExporter]
  8. [MemoryDiagnoser]
  9. public class LoggerBenchmark
  10. {
  11. MqttNetNullLogger _nullLogger;
  12. MqttNetSourceLogger _sourceNullLogger;
  13. MqttNetEventLogger _eventLogger;
  14. MqttNetSourceLogger _sourceEventLogger;
  15. MqttNetEventLogger _eventLoggerNoListener;
  16. MqttNetSourceLogger _sourceEventLoggerNoListener;
  17. bool _useHandler;
  18. [GlobalSetup]
  19. public void Setup()
  20. {
  21. _nullLogger = new MqttNetNullLogger();
  22. _sourceNullLogger = _nullLogger.WithSource("Source");
  23. _eventLogger = new MqttNetEventLogger();
  24. _eventLogger.LogMessagePublished += OnLogMessagePublished;
  25. _sourceEventLogger = _eventLogger.WithSource("Source");
  26. _eventLoggerNoListener = new MqttNetEventLogger();
  27. _sourceEventLoggerNoListener = _eventLoggerNoListener.WithSource("Source");
  28. }
  29. void OnLogMessagePublished(object sender, MqttNetLogMessagePublishedEventArgs eventArgs)
  30. {
  31. if (_useHandler)
  32. {
  33. eventArgs.LogMessage.ToString();
  34. }
  35. }
  36. [Benchmark]
  37. public void Log_10000_Messages_No_Listener()
  38. {
  39. _useHandler = false;
  40. for (var i = 0; i < 10000; i++)
  41. {
  42. _sourceEventLoggerNoListener.Verbose("test log message {0}", "parameter");
  43. }
  44. }
  45. [Benchmark]
  46. public void Log_10000_Messages_With_To_String()
  47. {
  48. _useHandler = true;
  49. for (var i = 0; i < 10000; i++)
  50. {
  51. _sourceEventLogger.Verbose("test log message {0}", "parameter");
  52. }
  53. }
  54. [Benchmark]
  55. public void Log_10000_Messages_Without_To_String()
  56. {
  57. _useHandler = false;
  58. for (var i = 0; i < 10000; i++)
  59. {
  60. _sourceEventLogger.Verbose("test log message {0}", "parameter");
  61. }
  62. }
  63. [Benchmark]
  64. public void Log_10000_Messages_With_NullLogger()
  65. {
  66. for (var i = 0; i < 10000; i++)
  67. {
  68. _sourceNullLogger.Verbose("test log message {0}", "parameter");
  69. }
  70. }
  71. }
  72. }