Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Miller committed Jan 19, 2024
1 parent 4178431 commit 1999fb2
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/Core/tests/Benchmarks/Benchmarks/VisualTreeBenchmarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using BenchmarkDotNet.Attributes;
using Microsoft.Maui.Controls;

namespace Microsoft.Maui.Benchmarks
{
[MemoryDiagnoser]
public class VisualTreeBenchmarker
{
static readonly View[] Views = [
new Border(), new BoxView(), new CarouselView(), new Grid(), new Entry(), new Picker(), new CollectionView(),
new CheckBox(), new DatePicker(), new Stepper(), new Slider(), new ActivityIndicator(), new Frame(),
new ContentView(), new ProgressBar(), new SearchBar(), new Switch(), new TimePicker(), new WebView(), new Button(),
];

private const int Iterations = 100;

[Benchmark]
public void GetVisualTreeElements()
{
var layout = new VerticalStackLayout();

for (int i = 0; i < Iterations; i++)
{
var childLayout = new VerticalStackLayout();

foreach (var view in Views)
{
childLayout.Add(view);

var grandchildLayout = new VerticalStackLayout();

foreach (var view2 in Views)
{
grandchildLayout.Add(view);
grandchildLayout.GetVisualTreeElements(grandchildLayout.Frame);
}

layout.Add(grandchildLayout);

childLayout.GetVisualTreeElements(childLayout.Frame);
}

layout.Add(childLayout);

layout.GetVisualTreeElements(layout.Frame);
}
}
}
}

0 comments on commit 1999fb2

Please sign in to comment.