PropertyAccessorPluginBenchmarks.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Collections.Generic;
  2. using Avalonia.Data.Core.Plugins;
  3. using BenchmarkDotNet.Attributes;
  4. namespace Avalonia.Benchmarks.Data
  5. {
  6. [MemoryDiagnoser, InProcess]
  7. public class PropertyAccessorPluginBenchmarks
  8. {
  9. private readonly AccessorTestObject _targetStrongRef = new AccessorTestObject();
  10. private readonly List<IPropertyAccessorPlugin> _oldPlugins;
  11. private readonly List<IPropertyAccessorPlugin> _newPlugins;
  12. public PropertyAccessorPluginBenchmarks()
  13. {
  14. _oldPlugins = new List<IPropertyAccessorPlugin>
  15. {
  16. new AvaloniaPropertyAccessorPlugin(),
  17. new ReflectionMethodAccessorPlugin(),
  18. new InpcPropertyAccessorPlugin()
  19. };
  20. _newPlugins = new List<IPropertyAccessorPlugin>
  21. {
  22. new AvaloniaPropertyAccessorPlugin(),
  23. new InpcPropertyAccessorPlugin(),
  24. new ReflectionMethodAccessorPlugin()
  25. };
  26. }
  27. [Benchmark]
  28. public void MatchAccessorOld()
  29. {
  30. var propertyName = nameof(AccessorTestObject.Test);
  31. foreach (IPropertyAccessorPlugin x in _oldPlugins)
  32. {
  33. if (x.Match(_targetStrongRef, propertyName))
  34. {
  35. break;
  36. }
  37. }
  38. }
  39. [Benchmark]
  40. public void MatchAccessorNew()
  41. {
  42. var propertyName = nameof(AccessorTestObject.Test);
  43. foreach (IPropertyAccessorPlugin x in _newPlugins)
  44. {
  45. if (x.Match(_targetStrongRef, propertyName))
  46. {
  47. break;
  48. }
  49. }
  50. }
  51. }
  52. }