InheritedProperties.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections.Generic;
  2. using System.Runtime.CompilerServices;
  3. using Avalonia.Controls;
  4. using Avalonia.UnitTests;
  5. using BenchmarkDotNet.Attributes;
  6. namespace Avalonia.Benchmarks.Data;
  7. [MemoryDiagnoser]
  8. public class InheritedProperties
  9. {
  10. private readonly TestRoot _root;
  11. private readonly List<Control> _controls = new();
  12. public InheritedProperties()
  13. {
  14. var panel = new StackPanel();
  15. _root = new TestRoot
  16. {
  17. Child = panel,
  18. Renderer = new NullRenderer()
  19. };
  20. _controls.Add(panel);
  21. _controls = ControlHierarchyCreator.CreateChildren(_controls, panel, 3, 5, 5);
  22. _root.LayoutManager.ExecuteInitialLayoutPass();
  23. }
  24. [Benchmark, MethodImpl(MethodImplOptions.NoInlining)]
  25. public void ChangeDataContext()
  26. {
  27. TestDataContext[] dataContexts = [new(), new(), new()];
  28. for (int i = 0; i < 100; i++)
  29. {
  30. for (int j = 0; j < dataContexts.Length; j++)
  31. {
  32. _root.DataContext = dataContexts[j];
  33. }
  34. }
  35. }
  36. public class TestDataContext;
  37. }