-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Benchmarks * Add `BenchmarkDotNet.Artifacts/` to `.gitignore` * Add Benchmarks to Build Pipeline * Update .gitignore * Only publish artifacts on Windows * Segregate View-to-ViewModel Bindings from ViewModel-To-View Bindings * Add missing setters * Update azure-pipelines.yml * Update Pipeline Order + Display Name * Move Benchmarks + Sample App to Separate Job Pipeline Running these in parallel optimizes our pipeline speeds * Update azure-pipelines.yml * Add `CommunityToolkit.Maui.Markup.Benchmarks.csproj` * Update azure-pipelines.yml * Update azure-pipelines.yml * Update Benchmark CI * Use `--project` * Update azure-pipelines.yml * Publish Benchmark Results to `$(Build.ArtifactStagingDirectory)` * Disable Code Signing * Update azure-pipelines.yml * Update azure-pipelines.yml * Update azure-pipelines.yml * Update azure-pipelines.yml * Update azure-pipelines.yml * Update azure-pipelines.yml
- Loading branch information
1 parent
4146d1f
commit 5d9ab90
Showing
17 changed files
with
662 additions
and
21 deletions.
There are no files selected for viewing
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
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
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
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,60 @@ | ||
using CommunityToolkit.Maui.Markup.Benchmarks.Mocks; | ||
|
||
namespace CommunityToolkit.Maui.Markup.Benchmarks; | ||
|
||
public abstract class BaseTest | ||
{ | ||
protected BaseTest() | ||
{ | ||
CreateAndSetMockApplication(out var serviceProvider); | ||
ServiceProvider = serviceProvider; | ||
} | ||
|
||
protected IServiceProvider ServiceProvider { get; } | ||
|
||
protected static TElementHandler CreateElementHandler<TElementHandler>(IElement view, bool hasMauiContext = true) | ||
where TElementHandler : IElementHandler, new() | ||
{ | ||
var mockElementHandler = new TElementHandler(); | ||
mockElementHandler.SetVirtualView(view); | ||
|
||
if (hasMauiContext) | ||
{ | ||
mockElementHandler.SetMauiContext(Application.Current?.Handler?.MauiContext ?? throw new NullReferenceException()); | ||
} | ||
|
||
return mockElementHandler; | ||
} | ||
|
||
protected static TViewHandler CreateViewHandler<TViewHandler>(IView view, bool hasMauiContext = true) | ||
where TViewHandler : IViewHandler, new() | ||
{ | ||
var mockViewHandler = new TViewHandler(); | ||
mockViewHandler.SetVirtualView(view); | ||
|
||
if (hasMauiContext) | ||
{ | ||
mockViewHandler.SetMauiContext(Application.Current?.Handler?.MauiContext ?? throw new NullReferenceException()); | ||
} | ||
|
||
return mockViewHandler; | ||
} | ||
|
||
static void CreateAndSetMockApplication(out IServiceProvider serviceProvider) | ||
{ | ||
var appBuilder = MauiApp.CreateBuilder() | ||
.UseMauiApp<MockApplication>(); | ||
|
||
appBuilder.Services.AddSingleton<IDispatcher>(_ => new MockDispatcherProvider().GetForCurrentThread()); | ||
|
||
var mauiApp = appBuilder.Build(); | ||
|
||
var application = mauiApp.Services.GetRequiredService<IApplication>(); | ||
serviceProvider = mauiApp.Services; | ||
|
||
IPlatformApplication.Current = (IPlatformApplication)application; | ||
|
||
application.Handler = new ApplicationHandlerStub(); | ||
application.Handler.SetMauiContext(new HandlersContextStub(mauiApp.Services)); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/CommunityToolkit.Maui.Markup.Benchmarks/Benchmarks/ExecuteBindingsBase.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,47 @@ | ||
using CommunityToolkit.Maui.Markup.Benchmarks.Extensions; | ||
|
||
namespace CommunityToolkit.Maui.Markup.Benchmarks; | ||
|
||
public abstract class ExecuteBindingsBase : BaseTest | ||
{ | ||
protected const string helloWorldText = "Hello World"; | ||
|
||
protected ExecuteBindingsBase() | ||
{ | ||
DefaultBindingsLabel = new() | ||
{ | ||
BindingContext = DefaultBindingsLabelViewModel | ||
}; | ||
DefaultBindingsLabel.SetBinding(Label.TextProperty, nameof(LabelViewModel.Text), mode: BindingMode.TwoWay); | ||
DefaultBindingsLabel.SetBinding(Label.TextColorProperty, nameof(LabelViewModel.TextColor), mode: BindingMode.TwoWay); | ||
DefaultBindingsLabel.EnableAnimations(); | ||
|
||
DefaultMarkupBindingsLabel = new Label | ||
{ | ||
BindingContext = DefaultMarkupBindingsLabelViewModel | ||
}.Bind(Label.TextProperty, nameof(LabelViewModel.Text), mode: BindingMode.TwoWay) | ||
.Bind(Label.TextColorProperty, nameof(LabelViewModel.TextColor), mode: BindingMode.TwoWay); | ||
DefaultMarkupBindingsLabel.EnableAnimations(); | ||
|
||
TypedMarkupBindingsLabel = new Label | ||
{ | ||
BindingContext = TypedMarkupBindingsLabelViewModel | ||
}.Bind(Label.TextProperty, | ||
getter: (LabelViewModel vm) => vm.Text, | ||
setter: (LabelViewModel vm, string text) => vm.Text = text, | ||
mode: BindingMode.TwoWay) | ||
.Bind(Label.TextColorProperty, | ||
getter: (LabelViewModel vm) => vm.TextColor, | ||
setter: (LabelViewModel vm, Color textColor) => vm.TextColor = textColor, | ||
mode: BindingMode.TwoWay); | ||
TypedMarkupBindingsLabel.EnableAnimations(); | ||
} | ||
|
||
protected LabelViewModel DefaultBindingsLabelViewModel { get; } = new(); | ||
protected LabelViewModel DefaultMarkupBindingsLabelViewModel { get; } = new(); | ||
protected LabelViewModel TypedMarkupBindingsLabelViewModel { get; } = new(); | ||
|
||
protected Label DefaultBindingsLabel { get; } | ||
protected Label DefaultMarkupBindingsLabel{ get; } | ||
protected Label TypedMarkupBindingsLabel{ get; } | ||
} |
28 changes: 28 additions & 0 deletions
28
src/CommunityToolkit.Maui.Markup.Benchmarks/Benchmarks/ExecuteBindings_ViewModelToView.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,28 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace CommunityToolkit.Maui.Markup.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class ExecuteBindings_ViewModelToView : ExecuteBindingsBase | ||
{ | ||
[Benchmark(Baseline = true)] | ||
public void ExecuteDefaultBindings_ViewModelToView() | ||
{ | ||
DefaultBindingsLabelViewModel.TextColor = Colors.Green; | ||
DefaultBindingsLabelViewModel.Text = helloWorldText; | ||
} | ||
|
||
[Benchmark] | ||
public void ExecuteDefaultBindingsMarkup_ViewModelToView() | ||
{ | ||
DefaultMarkupBindingsLabelViewModel.TextColor = Colors.Green; | ||
DefaultMarkupBindingsLabelViewModel.Text = helloWorldText; | ||
} | ||
|
||
[Benchmark] | ||
public void ExecuteTypedBindingsMarkup_ViewModelToView() | ||
{ | ||
TypedMarkupBindingsLabelViewModel.TextColor = Colors.Green; | ||
TypedMarkupBindingsLabelViewModel.Text = helloWorldText; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/CommunityToolkit.Maui.Markup.Benchmarks/Benchmarks/ExecuteBindings_ViewToViewModel.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,28 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace CommunityToolkit.Maui.Markup.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class ExecuteBindings_ViewToViewModel : ExecuteBindingsBase | ||
{ | ||
[Benchmark(Baseline = true)] | ||
public void ExecuteDefaultBindings_ViewToViewModel() | ||
{ | ||
DefaultBindingsLabel.TextColor = Colors.Green; | ||
DefaultBindingsLabel.Text = helloWorldText; | ||
} | ||
|
||
[Benchmark] | ||
public void ExecuteDefaultBindingsMarkup_ViewToViewModel() | ||
{ | ||
DefaultMarkupBindingsLabel.TextColor = Colors.Green; | ||
DefaultMarkupBindingsLabel.Text = helloWorldText; | ||
} | ||
|
||
[Benchmark] | ||
public void ExecuteTypedBindingsMarkup_ViewToViewModel() | ||
{ | ||
TypedMarkupBindingsLabel.TextColor = Colors.Green; | ||
TypedMarkupBindingsLabel.Text = helloWorldText; | ||
} | ||
} |
Oops, something went wrong.