diff --git a/src/SamplesApp/Benchmarks.Shared/Benchmarks.Shared.projitems b/src/SamplesApp/Benchmarks.Shared/Benchmarks.Shared.projitems index f01a634a8588..ee83a871be78 100644 --- a/src/SamplesApp/Benchmarks.Shared/Benchmarks.Shared.projitems +++ b/src/SamplesApp/Benchmarks.Shared/Benchmarks.Shared.projitems @@ -19,11 +19,13 @@ + + diff --git a/src/SamplesApp/Benchmarks.Shared/Controls/BenchmarkDotNetControl.xaml b/src/SamplesApp/Benchmarks.Shared/Controls/BenchmarkDotNetControl.xaml index e052276123a5..7e1baf49b419 100644 --- a/src/SamplesApp/Benchmarks.Shared/Controls/BenchmarkDotNetControl.xaml +++ b/src/SamplesApp/Benchmarks.Shared/Controls/BenchmarkDotNetControl.xaml @@ -25,14 +25,22 @@ - + + + + + + - + + + diff --git a/src/SamplesApp/Benchmarks.Shared/Controls/BenchmarkDotNetControl.xaml.cs b/src/SamplesApp/Benchmarks.Shared/Controls/BenchmarkDotNetControl.xaml.cs index 1b00bc1863a1..0fba9c07b52b 100644 --- a/src/SamplesApp/Benchmarks.Shared/Controls/BenchmarkDotNetControl.xaml.cs +++ b/src/SamplesApp/Benchmarks.Shared/Controls/BenchmarkDotNetControl.xaml.cs @@ -54,6 +54,8 @@ private async Task Run() { var config = new CoreConfig(_logger); + BenchmarkUIHost.Root = FindName("testHost") as ContentControl; + await SetStatus("Discovering benchmarks in " + BenchmarksBaseNamespace); var types = EnumerateBenchmarks(config).ToArray(); @@ -65,11 +67,15 @@ private async Task Run() await SetStatus($"Done."); } - catch(Exception e) + catch (Exception e) { await SetStatus($"Failed {e?.Message}"); _logger.WriteLine(LogKind.Error, e?.ToString()); } + finally + { + BenchmarkUIHost.Root = null; + } } private async Task SetStatus(string status) diff --git a/src/SamplesApp/Benchmarks.Shared/Controls/BenchmarkUIHost.cs b/src/SamplesApp/Benchmarks.Shared/Controls/BenchmarkUIHost.cs new file mode 100644 index 000000000000..d77cef8d50c7 --- /dev/null +++ b/src/SamplesApp/Benchmarks.Shared/Controls/BenchmarkUIHost.cs @@ -0,0 +1,9 @@ +using Windows.UI.Xaml.Controls; + +namespace Benchmarks.Shared.Controls +{ + internal class BenchmarkUIHost + { + public static ContentControl Root { get; internal set; } + } +} diff --git a/src/SamplesApp/Benchmarks.Shared/Suite/Windows_UI_Xaml_Controls/UIElementPerf/LoadUnloadPerf.cs b/src/SamplesApp/Benchmarks.Shared/Suite/Windows_UI_Xaml_Controls/UIElementPerf/LoadUnloadPerf.cs new file mode 100644 index 000000000000..0255371506fd --- /dev/null +++ b/src/SamplesApp/Benchmarks.Shared/Suite/Windows_UI_Xaml_Controls/UIElementPerf/LoadUnloadPerf.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Text; +using BenchmarkDotNet.Attributes; +using Benchmarks.Shared.Controls; +using Windows.Foundation; +using Windows.UI.Xaml.Controls; + +namespace SamplesApp.Benchmarks.Suite.Windows_UI_Xaml_Controls.GridBench +{ + public class LoadUnloadBenchmark + { + [Params(5, 10, 30)] + public int Depth { get; set; } + + private Grid SUT; + + [GlobalSetup] + public void Setup() + { + SUT = CreateHierachy(); + } + + [Benchmark()] + public void BasicLoadUnload() + { + var item = CreateHierachy(); + + for (int i = 0; i < 50; i++) + { + BenchmarkUIHost.Root.Content = item; + BenchmarkUIHost.Root.Content = null; + } + } + + private Grid CreateHierachy() + { + var top = new Grid(); + var current = top; + + for (int i = 0; i < Depth; i++) + { + var n = new Grid(); + current.Children.Add(n); + current = n; + } + + current.Children.Add(new TextBlock() { Text = "test" }); + + return top; + } + } +}