-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Edward Miller
committed
Jan 19, 2024
1 parent
a14a4cd
commit e6ddfeb
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/Core/tests/Benchmarks/Benchmarks/VisualTreeBenchmarker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |