7 changed files with 131 additions and 58 deletions
@ -0,0 +1,47 @@ |
|||
using System.ComponentModel; |
|||
using System.Runtime.CompilerServices; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Avalonia.Benchmarks.Data |
|||
{ |
|||
internal class AccessorTestObject : INotifyPropertyChanged |
|||
{ |
|||
private string _test; |
|||
|
|||
public string Test |
|||
{ |
|||
get => _test; |
|||
set |
|||
{ |
|||
if (_test == value) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
_test = value; |
|||
|
|||
OnPropertyChanged(); |
|||
} |
|||
} |
|||
|
|||
public event PropertyChangedEventHandler PropertyChanged; |
|||
|
|||
public void Execute() |
|||
{ |
|||
} |
|||
|
|||
public void Execute(object p0) |
|||
{ |
|||
} |
|||
|
|||
public void Execute(object p0, object p1) |
|||
{ |
|||
} |
|||
|
|||
[NotifyPropertyChangedInvocator] |
|||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) |
|||
{ |
|||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
using System.Collections.Generic; |
|||
using Avalonia.Data.Core.Plugins; |
|||
using BenchmarkDotNet.Attributes; |
|||
|
|||
namespace Avalonia.Benchmarks.Data |
|||
{ |
|||
[MemoryDiagnoser, InProcess] |
|||
public class PropertyAccessorPluginBenchmarks |
|||
{ |
|||
private readonly AccessorTestObject _targetStrongRef = new AccessorTestObject(); |
|||
|
|||
private readonly List<IPropertyAccessorPlugin> _oldPlugins; |
|||
private readonly List<IPropertyAccessorPlugin> _newPlugins; |
|||
|
|||
public PropertyAccessorPluginBenchmarks() |
|||
{ |
|||
_oldPlugins = new List<IPropertyAccessorPlugin> |
|||
{ |
|||
new AvaloniaPropertyAccessorPlugin(), |
|||
new MethodAccessorPlugin(), |
|||
new InpcPropertyAccessorPlugin() |
|||
}; |
|||
|
|||
_newPlugins = new List<IPropertyAccessorPlugin> |
|||
{ |
|||
new AvaloniaPropertyAccessorPlugin(), |
|||
new InpcPropertyAccessorPlugin(), |
|||
new MethodAccessorPlugin() |
|||
}; |
|||
} |
|||
|
|||
[Benchmark] |
|||
public void MatchAccessorOld() |
|||
{ |
|||
var propertyName = nameof(AccessorTestObject.Test); |
|||
|
|||
foreach (IPropertyAccessorPlugin x in _oldPlugins) |
|||
{ |
|||
if (x.Match(_targetStrongRef, propertyName)) |
|||
{ |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
[Benchmark] |
|||
public void MatchAccessorNew() |
|||
{ |
|||
var propertyName = nameof(AccessorTestObject.Test); |
|||
|
|||
foreach (IPropertyAccessorPlugin x in _newPlugins) |
|||
{ |
|||
if (x.Match(_targetStrongRef, propertyName)) |
|||
{ |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue