Skip to content

Commit

Permalink
feat: Add Load/Unload benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Dec 14, 2020
1 parent e53bfaa commit ba19901
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/SamplesApp/Benchmarks.Shared/Benchmarks.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Controls\BenchmarkUIHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Suite\SpanBench\SimpleSpanBenchmark.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\BenchmarkDotNetControl.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\BenchmarkDotNetTestsPage.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Suite\Windows_UI_Xaml\ResourceDictionaryBench\XamlControlsResourcesCreationBenchmark.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Suite\Windows_UI_Xaml\ResourceDictionaryBench\XamlControlsResourcesCreationRetrievalBenchmark.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Suite\Windows_UI_Xaml_Controls\UIElementPerf\LoadUnloadPerf.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Suite\Windows_UI_Xaml_Controls\DependencyPropertyBench\SimpleDPBenchmark.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Suite\Windows_UI_Xaml_Controls\UIElementPerf\UIElementCreationBenchmark.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Suite\Windows_UI_Xaml_Controls\GridBench\SimpleGridBenchmark.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@
<TextBlock x:Name="runStatus"
Text="Not initialized" />
</StackPanel>
<ScrollViewer Grid.Row="1"
Background="Black"
Padding="12">
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="0"
Background="Black"
Padding="12">
<TextBlock x:Name="runLogs"
Grid.Column="1"
FontFamily="Courier New"
FontSize="12"
IsTextSelectionEnabled="True" />
</ScrollViewer>
</ScrollViewer>
<ContentControl x:Name="testHost" />
</Grid>
</Grid>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/SamplesApp/Benchmarks.Shared/Controls/BenchmarkUIHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Windows.UI.Xaml.Controls;

namespace Benchmarks.Shared.Controls
{
internal class BenchmarkUIHost
{
public static ContentControl Root { get; internal set; }
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit ba19901

Please sign in to comment.