StyleAttachBenchmark.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using Avalonia.Controls;
  4. using Avalonia.UnitTests;
  5. using BenchmarkDotNet.Attributes;
  6. namespace Avalonia.Benchmarks.Styling
  7. {
  8. [MemoryDiagnoser]
  9. public class StyleAttachBenchmark : IDisposable
  10. {
  11. private readonly IDisposable _app;
  12. private readonly TestRoot _root;
  13. private readonly TextBox _control;
  14. public StyleAttachBenchmark()
  15. {
  16. _app = UnitTestApplication.Start(
  17. TestServices.StyledWindow.With(
  18. renderInterface: new NullRenderingPlatform(),
  19. threadingInterface: new NullThreadingPlatform()));
  20. _root = new TestRoot(true, null)
  21. {
  22. Renderer = new NullRenderer(),
  23. };
  24. _control = new TextBox();
  25. }
  26. [Benchmark]
  27. [MethodImpl(MethodImplOptions.NoInlining)]
  28. public void AttachTextBoxStyles()
  29. {
  30. var styles = UnitTestApplication.Current.Styles;
  31. styles.Attach(_control, UnitTestApplication.Current);
  32. styles.Detach();
  33. }
  34. public void Dispose()
  35. {
  36. _app.Dispose();
  37. }
  38. }
  39. }