csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
using Avalonia.Data;
|
|
using BenchmarkDotNet.Attributes;
|
|
|
|
namespace Avalonia.Benchmarks.Data
|
|
{
|
|
[MemoryDiagnoser, InProcess]
|
|
public class BindingsBenchmark
|
|
{
|
|
[Benchmark]
|
|
public void TwoWayBinding_Via_Binding()
|
|
{
|
|
var instance = new TestClass();
|
|
|
|
var binding = new Binding(nameof(TestClass.BoundValue), BindingMode.TwoWay)
|
|
{
|
|
Source = instance
|
|
};
|
|
|
|
instance.Bind(TestClass.IntValueProperty, binding);
|
|
}
|
|
|
|
[Benchmark]
|
|
public void UpdateTwoWayBinding_Via_Binding()
|
|
{
|
|
var instance = new TestClass();
|
|
|
|
var binding = new Binding(nameof(TestClass.BoundValue), BindingMode.TwoWay)
|
|
{
|
|
Source = instance
|
|
};
|
|
|
|
instance.Bind(TestClass.IntValueProperty, binding);
|
|
for (int i = 0; i < 60; i++)
|
|
{
|
|
instance.IntValue = i;
|
|
}
|
|
}
|
|
private class TestClass : AvaloniaObject
|
|
{
|
|
public static readonly StyledProperty<int> IntValueProperty =
|
|
AvaloniaProperty.Register<TestClass, int>(nameof(IntValue));
|
|
|
|
public static readonly StyledProperty<int> BoundValueProperty =
|
|
AvaloniaProperty.Register<TestClass, int>(nameof(BoundValue));
|
|
|
|
public int IntValue
|
|
{
|
|
get => GetValue(IntValueProperty);
|
|
set => SetValue(IntValueProperty, value);
|
|
}
|
|
|
|
public int BoundValue
|
|
{
|
|
get => GetValue(BoundValueProperty);
|
|
set => SetValue(BoundValueProperty, value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|