Browse Source

Remove dependency on fluent theme.

pull/7971/head
Dariusz Komosiński 5 years ago
parent
commit
a2bcd8a9c9
  1. 17
      tests/Avalonia.Benchmarks/Styling/ResourceBenchmarks.cs
  2. 29
      tests/Avalonia.Benchmarks/TestStyles.cs

17
tests/Avalonia.Benchmarks/Styling/ResourceBenchmarks.cs

@ -3,7 +3,6 @@ using Avalonia.Controls;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.PlatformSupport; using Avalonia.PlatformSupport;
using Avalonia.Styling; using Avalonia.Styling;
using Avalonia.Themes.Fluent;
using Avalonia.UnitTests; using Avalonia.UnitTests;
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using Moq; using Moq;
@ -25,7 +24,7 @@ namespace Avalonia.Benchmarks.Styling
renderInterface: new MockPlatformRenderInterface(), renderInterface: new MockPlatformRenderInterface(),
standardCursorFactory: Mock.Of<ICursorFactory>(), standardCursorFactory: Mock.Of<ICursorFactory>(),
styler: new Styler(), styler: new Styler(),
theme: () => LoadTheme(), theme: () => CreateTheme(),
threadingInterface: new NullThreadingPlatform(), threadingInterface: new NullThreadingPlatform(),
fontManagerImpl: new MockFontManagerImpl(), fontManagerImpl: new MockFontManagerImpl(),
textShaperImpl: new MockTextShaperImpl(), textShaperImpl: new MockTextShaperImpl(),
@ -34,7 +33,7 @@ namespace Avalonia.Benchmarks.Styling
return UnitTestApplication.Start(services); return UnitTestApplication.Start(services);
} }
private static Styles LoadTheme() private static Styles CreateTheme()
{ {
AssetLoader.RegisterResUriParsers(); AssetLoader.RegisterResUriParsers();
@ -43,11 +42,11 @@ namespace Avalonia.Benchmarks.Styling
var postHost = new Style(); var postHost = new Style();
postHost.Resources.Add("postTheme", null); postHost.Resources.Add("postTheme", null);
return new Styles return new Styles
{ {
preHost, preHost,
new FluentTheme(new Uri("avares://Avalonia.Benchmarks")), new TestStyles(50, 3, 5),
postHost postHost
}; };
} }
@ -81,11 +80,13 @@ namespace Avalonia.Benchmarks.Styling
current.Child = _searchStart; current.Child = _searchStart;
} }
private const int LookupCount = 100;
[Benchmark] [Benchmark]
public void FindPreResource() public void FindPreResource()
{ {
for (int i = 0; i < 100; ++i) for (int i = 0; i < LookupCount; ++i)
{ {
_searchStart.FindResource("preTheme"); _searchStart.FindResource("preTheme");
} }
@ -94,7 +95,7 @@ namespace Avalonia.Benchmarks.Styling
[Benchmark] [Benchmark]
public void FindPostResource() public void FindPostResource()
{ {
for (int i = 0; i < 100; ++i) for (int i = 0; i < LookupCount; ++i)
{ {
_searchStart.FindResource("postTheme"); _searchStart.FindResource("postTheme");
} }
@ -103,7 +104,7 @@ namespace Avalonia.Benchmarks.Styling
[Benchmark] [Benchmark]
public void FindNotExistingResource() public void FindNotExistingResource()
{ {
for (int i = 0; i < 100; ++i) for (int i = 0; i < LookupCount; ++i)
{ {
_searchStart.FindResource("notPresent"); _searchStart.FindResource("notPresent");
} }

29
tests/Avalonia.Benchmarks/TestStyles.cs

@ -0,0 +1,29 @@
using Avalonia.Styling;
namespace Avalonia.Benchmarks
{
public class TestStyles : Styles
{
public TestStyles(int childStylesCount, int childInnerStyleCount, int childResourceCount)
{
for (int i = 0; i < childStylesCount; i++)
{
var childStyles = new Styles();
for (int j = 0; j < childInnerStyleCount; j++)
{
var childStyle = new Style();
for (int k = 0; k < childResourceCount; k++)
{
childStyle.Resources.Add($"resource.{i}.{j}.{k}", null);
}
childStyles.Add(childStyle);
}
Add(childStyles);
}
}
}
}
Loading…
Cancel
Save