CalendarBenchmark.cs 1.1 KB

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