Browse Source

Merge pull request #5888 from AvaloniaUI/benchmarks/theme-loading-benchmark

Theme loading benchmark
pull/5909/head
Dan Walmsley 5 years ago
committed by GitHub
parent
commit
7dd44a90e8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 63
      tests/Avalonia.Benchmarks/Themes/ThemeBenchmark.cs

63
tests/Avalonia.Benchmarks/Themes/ThemeBenchmark.cs

@ -0,0 +1,63 @@
using System;
using Avalonia.Controls;
using Avalonia.Markup.Xaml.Styling;
using Avalonia.Shared.PlatformSupport;
using Avalonia.Styling;
using Avalonia.UnitTests;
using BenchmarkDotNet.Attributes;
namespace Avalonia.Benchmarks.Themes
{
[MemoryDiagnoser]
public class ThemeBenchmark : IDisposable
{
private IDisposable _app;
public ThemeBenchmark()
{
AssetLoader.RegisterResUriParsers();
_app = UnitTestApplication.Start(TestServices.StyledWindow.With(theme: () => null));
// Add empty style to override it later
UnitTestApplication.Current.Styles.Add(new Style());
}
[Benchmark]
[Arguments("avares://Avalonia.Themes.Fluent/FluentDark.xaml")]
[Arguments("avares://Avalonia.Themes.Fluent/FluentLight.xaml")]
public bool InitFluentTheme(string themeUri)
{
UnitTestApplication.Current.Styles[0] = new StyleInclude(new Uri("resm:Styles?assembly=Avalonia.Benchmarks"))
{
Source = new Uri(themeUri)
};
return ((IResourceHost)UnitTestApplication.Current).TryGetResource("SystemAccentColor", out _);
}
[Benchmark]
[Arguments("avares://Avalonia.Themes.Default/Accents/BaseLight.xaml")]
[Arguments("avares://Avalonia.Themes.Default/Accents/BaseDark.xaml")]
public bool InitDefaultTheme(string themeUri)
{
UnitTestApplication.Current.Styles[0] = new Styles
{
new StyleInclude(new Uri("resm:Styles?assembly=Avalonia.Benchmarks"))
{
Source = new Uri(themeUri)
},
new StyleInclude(new Uri("resm:Styles?assembly=Avalonia.Benchmarks"))
{
Source = new Uri("avares://Avalonia.Themes.Default/DefaultTheme.xaml")
}
};
return ((IResourceHost)UnitTestApplication.Current).TryGetResource("ThemeAccentColor", out _);
}
public void Dispose()
{
_app.Dispose();
}
}
}
Loading…
Cancel
Save